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


PHP Provider::tryUnreserveShipmentItem方法代码示例

本文整理汇总了PHP中Provider::tryUnreserveShipmentItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::tryUnreserveShipmentItem方法的具体用法?PHP Provider::tryUnreserveShipmentItem怎么用?PHP Provider::tryUnreserveShipmentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Provider的用法示例。


在下文中一共展示了Provider::tryUnreserveShipmentItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: transferItem2SystemShipment

 /**
  * @param ShipmentItem $sourceItem
  * @param $quantity
  * @return Result
  * @throws Main\ArgumentException
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotSupportedException
  */
 private function transferItem2SystemShipment(ShipmentItem $sourceItem, $quantity)
 {
     /** @var ShipmentItemCollection $sourceItemCollection */
     $sourceItemCollection = $sourceItem->getCollection();
     if ($this !== $sourceItemCollection->getShipment()) {
         throw new Main\ArgumentException("item");
     }
     $quantity = floatval($quantity);
     /** @var ShipmentCollection $shipmentCollection */
     $shipmentCollection = $this->getCollection();
     /** @var Shipment $systemShipment */
     $systemShipment = $shipmentCollection->getSystemShipment();
     /** @var BasketItem $basketItem */
     $basketItem = $sourceItem->getBasketItem();
     $shipmentItemCode = $sourceItem->getBasketCode();
     if ($quantity === 0) {
         return new Result();
     }
     /** @var ShipmentItemCollection $systemShipmentItemCollection */
     $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
     $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($shipmentItemCode);
     if (is_null($systemShipmentItem)) {
         $systemShipmentItem = $systemShipmentItemCollection->createItem($basketItem);
     }
     $newSystemShipmentItemQuantity = $systemShipmentItem->getQuantity() + $quantity;
     if ($newSystemShipmentItemQuantity < 0) {
         $result = new Result();
         $result->addError(new ResultError(str_replace(array("#NAME#", "#QUANTITY#"), array($sourceItem->getBasketItem()->getField("NAME"), abs($quantity)), Loc::getMessage('SALE_SHIPMENT_QUANTITY_MISMATCH')), 'SALE_SHIPMENT_QUANTITY_MISMATCH'));
         return $result;
     }
     $systemShipmentItem->setFieldNoDemand('QUANTITY', $newSystemShipmentItemQuantity);
     $affectedQuantity = 0;
     if ($quantity > 0) {
         if ($sourceItem->getReservedQuantity() > 0) {
             $affectedQuantity = $quantity;
             $originalQuantity = $sourceItem->getQuantity() + $quantity;
             if ($sourceItem->getReservedQuantity() < $originalQuantity) {
                 $affectedQuantity -= $originalQuantity - $sourceItem->getReservedQuantity();
             }
         }
     } elseif ($quantity < 0) {
         if ($systemShipmentItem->getReservedQuantity() > 0) {
             $affectedQuantity = $quantity;
             if ($systemShipmentItem->getReservedQuantity() < -$affectedQuantity) {
                 $affectedQuantity = -1 * $systemShipmentItem->getReservedQuantity();
             }
         }
     }
     if ($affectedQuantity != 0) {
         $result = $sourceItem->setField("RESERVED_QUANTITY", $sourceItem->getField('RESERVED_QUANTITY') - $affectedQuantity);
         //			if (!$result->isSuccess(true))
         //				return $result;
         $systemShipmentItem->setFieldNoDemand('RESERVED_QUANTITY', $systemShipmentItem->getField('RESERVED_QUANTITY') + $affectedQuantity);
     }
     $tryReserveResult = null;
     if ($quantity > 0) {
         if ($systemShipment->needReservation()) {
             /** @var Result $tryReserveResult */
             $tryReserveResult = Provider::tryReserveShipmentItem($systemShipmentItem);
         } else {
             /** @var Result $tryReserveResult */
             $tryReserveResult = Provider::tryUnreserveShipmentItem($systemShipmentItem);
         }
     } elseif ($quantity < 0) {
         if ($sourceItemCollection->getShipment()->needReservation()) {
             /** @var Result $tryReserveResult */
             $tryReserveResult = Provider::tryReserveShipmentItem($sourceItem);
         }
     }
     $canReserve = false;
     if ($tryReserveResult === null) {
         $canReserve = true;
     }
     if ($tryReserveResult !== null && ($tryReserveResult->isSuccess() && ($tryReserveResultData = $tryReserveResult->getData()))) {
         if (array_key_exists('CAN_RESERVE', $tryReserveResultData)) {
             $canReserve = $tryReserveResultData['CAN_RESERVE'];
         }
     }
     if ($systemShipment->needReservation() && $canReserve) {
         $systemShipment->updateReservedFlag();
     }
     return new Result();
 }
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:91,代码来源:shipment.php

示例2: tryUnreserve

 /**
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotSupportedException
  * @throws \Exception
  */
 public function tryUnreserve()
 {
     return Provider::tryUnreserveShipmentItem($this);
 }
开发者ID:webgksupport,项目名称:alpina,代码行数:9,代码来源:shipmentitem.php


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