当前位置: 首页>>代码示例>>PHP>>正文


PHP Provider::reserveBasketItem方法代码示例

本文整理汇总了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");
//.........这里部分代码省略.........
开发者ID:Satariall,项目名称:izurit,代码行数:101,代码来源:providerbase.php


注:本文中的Provider::reserveBasketItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。