本文整理汇总了PHP中Provider::reserveBasketItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::reserveBasketItem方法的具体用法?PHP Provider::reserveBasketItem怎么用?PHP Provider::reserveBasketItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Provider
的用法示例。
在下文中一共展示了Provider::reserveBasketItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyPoolReservation
/**
* @param Order $order
* @return Result
* @throws NotImplementedException
* @throws NotSupportedException
* @throws SystemException
*/
private static function applyPoolReservation(Order $order)
{
if (!isset(static::$reservationPool[$order->getInternalId()])) {
return new Result();
}
$result = new Result();
$pool = static::getReservationPool($order->getInternalId());
$poolQuantities = $pool->getQuantities();
$poolItems = $pool->getItems();
$shipmentCollection = $order->getShipmentCollection();
foreach ($poolQuantities as $basketCode => $quantity) {
$quantity = round($quantity, 4);
if ($quantity == 0) {
continue;
}
if (!isset($poolItems[$basketCode])) {
throw new SystemException();
}
/** @var BasketItem $basketItem */
$basketItem = $poolItems[$basketCode];
$canReserve = false;
/** @var Result $r */
$r = Provider::reserveBasketItem($basketItem, $quantity);
if ($r->isSuccess()) {
$reserveBasketItemResult = $r->getData();
$reservedQuantity = null;
if (!empty($reserveBasketItemResult) && is_array($reserveBasketItemResult)) {
if (array_key_exists('QUANTITY', $reserveBasketItemResult)) {
$reservedQuantity = round($reserveBasketItemResult['QUANTITY'], 4);
}
if (array_key_exists('HAS_PROVIDER', $reserveBasketItemResult)) {
$canReserve = $reserveBasketItemResult['HAS_PROVIDER'];
}
}
if ($reservedQuantity === null) {
$result->addError(new ResultError(Loc::getMessage('SALE_PROVIDER_RESERVE_BASKET_ITEM_WRONG_QUANTITY'), 'SALE_PROVIDER_RESERVE_BASKET_ITEM_WRONG_QUANTITY'));
}
} else {
$result->addErrors($r->getErrors());
}
if (!$result->isSuccess()) {
return $result;
}
$pool->set($basketItem, 0);
if ($quantity > 0 && $reservedQuantity > $quantity || $quantity < 0 && $reservedQuantity < $quantity) {
$result->addError(new ResultError(Loc::getMessage('SALE_PROVIDER_RESERVE_BASKET_ITEM_QUANTITY_NOT_ENOUGH'), 'SALE_PROVIDER_RESERVE_BASKET_ITEM_QUANTITY_NOT_ENOUGH'));
return $result;
}
// not implemented yet
if ($quantity < 0 && $reservedQuantity != $quantity) {
throw new NotImplementedException();
}
if ($canReserve && Configuration::isEnabledReservation() && $quantity != $reservedQuantity) {
$systemShipment = $shipmentCollection->getSystemShipment();
/** @var ShipmentItemCollection $systemShipmentItemCollection */
$systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
if ($shipmentItem = $systemShipmentItemCollection->getItemByBasketCode($basketCode)) {
if ($shipmentItem->getReservedQuantity() > 0) {
$needQuantity = $quantity - $reservedQuantity;
if ($shipmentItem->getReservedQuantity() >= $needQuantity) {
$setQuantity = $shipmentItem->getReservedQuantity() - $needQuantity;
} else {
$setQuantity = 0;
$needQuantity = $shipmentItem->getReservedQuantity();
}
$reservedQuantity += $needQuantity;
$shipmentItem->setField('RESERVED_QUANTITY', $setQuantity);
}
}
if ($quantity != $reservedQuantity) {
$diffQuantity = $quantity - $reservedQuantity;
/** @var Shipment $shipment */
foreach ($shipmentCollection as $shipment) {
if ($shipment->isSystem()) {
continue;
}
/** @var ShipmentItemCollection $shipmentItemCollection */
$shipmentItemCollection = $shipment->getShipmentItemCollection();
if ($shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketCode)) {
if ($shipmentItem->getReservedQuantity() >= $diffQuantity) {
$shipmentItem->setField('RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() - $diffQuantity);
$diffQuantity = 0;
break;
} else {
$diffQuantity -= $shipmentItem->getReservedQuantity();
$shipmentItem->setField('RESERVED_QUANTITY', 0);
}
}
}
if ($diffQuantity > 0 && $reservedQuantity > 0) {
$result->addError(new ResultError(Loc::getMessage('SALE_PROVIDER_RESERVE_BASKET_ITEM_QUANTITY_WRONG_RESIDUE'), 'SALE_PROVIDER_RESERVE_BASKET_ITEM_QUANTITY_WRONG_RESIDUE'));
return $result;
// throw new SystemException("diffQuantity");
//.........这里部分代码省略.........