クラス
ErrorStore
ソース ソース
ファイル: src/ErrorStore.php
class ErrorStore extends BaseErrorStore
{
const SKU_NOT_FOUND = 'SkuNotFound';
const COMBO_GROUP_NOT_FOUND = 'ComboGroupNotFound';
const COMBO_GROUP_IS_REQUIRED = 'ComboGroupIsRequired';
const GROUP_ITEM_NOT_FOUND = 'GroupItemNotFound';
const COMBO_SET_NOT_FOUND_BY_SKU_META_ID = 'ComboSetNotFoundBySkuMetaId';
const COMBO_SET_NOT_FOUND_BY_SKU_CODE = 'ComboSetNotFoundBySkuCode';
const COMBO_SET_NOT_FOUND_BY_ID = 'ComboSetNotFoundById';
const COMBO_SET_ALREADY_EXISTS = 'ComboSetAlreadyExists';
const COMBO_SET_DIVISION_INVALID = 'ComboSetDivisionInvalid';
const REQUIRED_FIELDS_MISSING = 'RequiredFieldsMissing';
const SKU_IS_COMBO_SET_GROUP_ITEM = 'SkuIsComboSetGroupItem';
const SKU_IS_COMBO_SET = 'SkuIsComboSet';
const INVALID_CHARGE_TYPE_COMBINATION = 'InvalidChargeTypeCombination';
/**
* Declares all `GenericError` objects
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public function populate() {
$defaultError = $this->getErrorCodeMap()[parent::INTERNAL_SERVER_ERROR];
$defaultMessage = $defaultError->message;
$mes = function ($skuMetaId) {
return sprintf(
// translators: Welcart SKU meta ID
__('An SKU with the meta ID "%d" does not exist', 'wcexics'),
$skuMetaId
);
};
$this->addError(new GenericError(
self::SKU_NOT_FOUND,
$this->getConstantNameByValue(self::SKU_NOT_FOUND),
404,
$mes,
__('This item is no longer available', 'wcexics'),
__('This SKU doesnt exist. Please refresh the page to see up-to-date info for this combo-set', 'wcexics')
));
$mes = function ($groupId) {
return sprintf(
// translators: Combo group ID
__('A combo group with the group ID "%d" does not exist', 'wcexics'),
$groupId
);
};
$this->addError(new GenericError(
self::COMBO_GROUP_NOT_FOUND,
$this->getConstantNameByValue(self::COMBO_GROUP_NOT_FOUND),
404,
$mes,
__('Selections for this combo-set item have been updated. Please refresh the page and try again.', 'wcexics'),
$mes
));
$mes = function ($itemId) {
return sprintf(
// translators: Group item ID
__('A group item with the item ID "%d" does not exist', 'wcexics'),
$itemId
);
};
$this->addError(new GenericError(
self::GROUP_ITEM_NOT_FOUND,
$this->getConstantNameByValue(self::GROUP_ITEM_NOT_FOUND),
404,
$mes,
__('Selections for this combo-set item have been updated. Please refresh the page and try again.', 'wcexics'),
__('This group item doesnt exist. Please refresh the page to see up-to-date info for this combo-set', 'wcexics')
));
$debug = function (ComboGroup $group) {
return sprintf(
// translators: Group ID
__('Group ID "%d" is required but no items were provided.', 'wcexics'),
$group->getId()
);
};
$mes = function (ComboGroup $group) {
return sprintf(
// translators: Group name
__('Please choose an item for "%s"', 'wcexics'),
$group->getLabel()
);
};
$this->addError(new GenericError(
self::COMBO_GROUP_IS_REQUIRED,
$this->getConstantNameByValue(self::COMBO_GROUP_IS_REQUIRED),
400,
$debug,
$mes,
$debug
));
$mes = function ($skuMetaId) {
return sprintf(
// translators: Combo-set item SKU meta ID
__('A combo-set item with the SKU meta ID "%d" does not exist', 'wcexics'),
(int)$skuMetaId
);
};
$this->addError(new GenericError(
self::COMBO_SET_NOT_FOUND_BY_SKU_META_ID,
$this->getConstantNameByValue(self::COMBO_SET_NOT_FOUND_BY_SKU_META_ID),
404,
$mes,
__('This item is no longer available', 'wcexics'),
__('This combo-set doesnt exist. Please refresh the page to see up-to-date info for this combo-set', 'wcexics')
));
$mes = function ($post_id, $skucode) {
return sprintf(
// translators: 1. Post ID 2. SKU code
__('A combo-set item with the post ID "%1$d" and SKU code "%2$s" does not exist', 'wcexics'),
(int)$post_id,
(string)$skucode
);
};
$this->addError(new GenericError(
self::COMBO_SET_NOT_FOUND_BY_SKU_CODE,
$this->getConstantNameByValue(self::COMBO_SET_NOT_FOUND_BY_SKU_CODE),
404,
$mes,
__('This item is no longer available', 'wcexics'),
__('This SKU doesnt exist. Please refresh the page to see up-to-date info for this combo-set', 'wcexics')
));
$mes = function ($comboSetId) {
return sprintf(
// translators: Combo-set ID
__('A combo-set item with the ID "%d" does not exist', 'wcexics'),
(int)$comboSetId
);
};
$this->addError(new GenericError(
self::COMBO_SET_NOT_FOUND_BY_ID,
$this->getConstantNameByValue(self::COMBO_SET_NOT_FOUND_BY_ID),
404,
$mes,
__('Selections for this combo-set item have been updated. Please refresh the page and try again.', 'wcexics'),
$mes
));
$this->addError(new GenericError(
self::REQUIRED_FIELDS_MISSING,
$this->getConstantNameByValue(self::REQUIRED_FIELDS_MISSING),
400,
function ($field) {
return sprintf(
// translators: The missing field
__('The field "%s" is required.', 'wcexics'),
$field
);
},
function ($message = '') use ($defaultMessage) {
return !empty($message) ? $message : $defaultMessage;
}
));
$mes = __('This SKU is already in use by another combo-set.', 'wcexics');
$this->addError(new GenericError(
self::SKU_IS_COMBO_SET_GROUP_ITEM,
$this->getConstantNameByValue(self::SKU_IS_COMBO_SET_GROUP_ITEM),
409,
$mes,
$mes
));
$mes = __('This SKU is a combo-set. It cannot be added as a group item', 'wcexics');
$this->addError(new GenericError(
self::SKU_IS_COMBO_SET,
$this->getConstantNameByValue(self::SKU_IS_COMBO_SET),
409,
$mes,
$mes
));
$mes = __('This SKU is already a combo-set', 'wcexics');
$this->addError(new GenericError(
self::COMBO_SET_ALREADY_EXISTS,
$this->getConstantNameByValue(self::COMBO_SET_ALREADY_EXISTS),
409,
$mes,
$mes
));
$this->addError(new GenericError(
self::COMBO_SET_DIVISION_INVALID,
$this->getConstantNameByValue(self::COMBO_SET_DIVISION_INVALID),
409,
function ($division, $gidivision, $details = '') {
return sprintf(
join(
' ',
[
// translators: 1. the combo-set item division 2. the invalid group item division
__('Invalid division: the combo-set division is "%1$s" but at least one of the items is "%2$s".', 'wcexics'),
trim($details),
]
),
$division,
$gidivision
);
},
__('This combination of items is not allowed', 'wcexics')
));
$mes = function ($cschargetype, $gichargetype) {
return sprintf(
// translators: 1. the group item charge type 2. the combo-set charge type
__('An item with a charge type of "%1$s" cannot be added to a combo-set whose charge type is "%2$s".', 'wcexics'),
$gichargetype,
$cschargetype
);
};
$this->addError(new GenericError(
self::INVALID_CHARGE_TYPE_COMBINATION,
$this->getConstantNameByValue(self::INVALID_CHARGE_TYPE_COMBINATION),
409,
$mes,
__('This combination of items is not allowed', 'wcexics'),
$mes
));
}
}
- populate — Declares all `GenericError` objects