本文整理汇总了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();
}
示例2: tryUnreserve
/**
* @throws Main\ArgumentOutOfRangeException
* @throws Main\NotSupportedException
* @throws \Exception
*/
public function tryUnreserve()
{
return Provider::tryUnreserveShipmentItem($this);
}