関数
PurchaseSanityChecks::comboSetSelectionsAreValid( int $comboSetId, array $grouptoitemmap )
パラメータ パラメータ
- $comboSetId
(数値) (必須)
- $grouptoitemmap
(配列) (必須)
ファイル: src/API/PurchaseSanityChecks.php
public static function comboSetSelectionsAreValid($comboSetId, $grouptoitemmap) { $comboSetId = (int)$comboSetId; $comboset = ComboSet::getComboSetById($comboSetId); if ($comboset instanceof GenericError) { return $comboset; } $grouptoitemmap = Cart::sanitizeComboSetSelections($grouptoitemmap); // check that all required groups have selections foreach ($comboset->getGroups() as $group) { if ($group->getOptional() === false) { // if the required group has at least one item but no item is selected, abort if (count($group->getItems()) > 0 && empty($grouptoitemmap[$group->getId()])) { return Master::getErrorStore()->getErrorResponse( ErrorStore::COMBO_GROUP_IS_REQUIRED, [$group], [$group], [$group] ); } } } // check that all selected groups and items exist foreach ($grouptoitemmap as $groupid => $itemids) { $group = ComboGroup::getComboGroupById($groupid); // if the group does not exist OR it is not associated with the combo-set, abort if ($group === null || $group->getComboSetId() !== $comboset->getId()) { return Master::getErrorStore()->getErrorResponse( ErrorStore::COMBO_GROUP_NOT_FOUND, [$groupid], [], [$groupid] ); } foreach ($itemids as $itemid) { $item = GroupItem::getGroupItemById($itemid); // if the item does not exist OR it is not associated with the group, abort if ($item === null || $item->getGroupId() !== $group->getId()) { return Master::getErrorStore()->getErrorResponse( ErrorStore::GROUP_ITEM_NOT_FOUND, [$itemid], [], [$itemid] ); } } } return true; }