本文整理汇总了PHP中Provider::tryReserveShipmentItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::tryReserveShipmentItem方法的具体用法?PHP Provider::tryReserveShipmentItem怎么用?PHP Provider::tryReserveShipmentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Provider
的用法示例。
在下文中一共展示了Provider::tryReserveShipmentItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tryReserve
/**
* @throws Main\ArgumentOutOfRangeException
* @throws Main\NotSupportedException
* @throws \Exception
*/
public function tryReserve()
{
return Provider::tryReserveShipmentItem($this);
}
示例2: syncQuantityAfterModify
/**
* @internal
*
* @param BasketItem $basketItem
* @param $value
* @param $oldValue
*
* @return Result
*/
public function syncQuantityAfterModify(BasketItem $basketItem, $value = null, $oldValue = null)
{
$result = new Result();
$shipmentItemCollection = $this->getShipmentItemCollection();
$shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode());
if ($shipmentItem === null) {
if ($value == 0) {
return new Result();
}
$shipmentItem = $shipmentItemCollection->createItem($basketItem);
}
$deltaQuantity = $value - $oldValue;
if ($deltaQuantity > 0) {
$shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity);
if ($this->needReservation()) {
Provider::tryReserveShipmentItem($shipmentItem);
}
} else {
if (floatval($shipmentItem->getField("QUANTITY")) <= 0) {
return new Result();
}
if ($value != 0 && $shipmentItem->getField("QUANTITY") < -$deltaQuantity) {
$result = new Result();
$result->addError(new ResultError(str_replace(array("#NAME#", "#QUANTITY#", "#DELTA_QUANTITY#"), array($basketItem->getField("NAME"), $shipmentItem->getField("QUANTITY"), abs($deltaQuantity)), Loc::getMessage('SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR')), 'SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR'));
return $result;
}
if ($value > 0) {
$shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity);
if ($this->needReservation()) {
Provider::tryReserveShipmentItem($shipmentItem);
}
} else {
$shipmentItem->setFieldNoDemand("QUANTITY", 0);
}
}
return $result;
}
示例3: onBasketModify
/**
* @param $action
* @param BasketItem $basketItem
* @param null $name
* @param null $oldValue
* @param null $value
*/
public function onBasketModify($action, BasketItem $basketItem, $name = null, $oldValue = null, $value = null)
{
switch ($action) {
case "UPDATE":
if ($name == "QUANTITY") {
/** @var ShipmentItemCollection $collection */
$collection = $this->getCollection();
$shipment = $collection->getShipment();
if ($shipment->isShipped() != "Y") {
return true;
}
if ($basketItem->getBasketCode() != $this->getBasketCode()) {
return true;
}
$quantity = $value - $oldValue;
if ($quantity != 0) {
$result = Provider::tryReserveShipmentItem($this);
}
if (!empty($result) && is_array($result)) {
$this->setField('RESERVED_QUANTITY', $result['QUANTITY']);
if ($quantity > 0) {
if ($this->getQuantity() != $this->getReservedQuantity()) {
/** @var ShipmentItemCollection $shipmentItemCollection */
$shipmentItemCollection = $this->getCollection();
/** @var Shipment $shipment */
$shipment = $shipmentItemCollection->getShipment();
$shipment->setMark();
}
}
}
}
//change quantity
break;
case "DELETE":
// unreserve
break;
}
}