本文整理汇总了PHP中Magento\Sales\Model\Order\Item::getQtyToShip方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::getQtyToShip方法的具体用法?PHP Item::getQtyToShip怎么用?PHP Item::getQtyToShip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Item
的用法示例。
在下文中一共展示了Item::getQtyToShip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canShipItem
/**
* Checks if order item can be shipped.
*
* Dummy item can be shipped or with his children or
* with parent item which is included to shipment.
*
* @param \Magento\Sales\Model\Order\Item $item
* @param array $items
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function canShipItem($item, array $items = [])
{
if ($item->getIsVirtual() || $item->getLockedDoShip()) {
return false;
}
if ($item->isDummy(true)) {
if ($item->getHasChildren()) {
if ($item->isShipSeparately()) {
return true;
}
foreach ($item->getChildrenItems() as $child) {
if ($child->getIsVirtual()) {
continue;
}
if (empty($items)) {
if ($child->getQtyToShip() > 0) {
return true;
}
} else {
if (isset($items[$child->getId()]) && $items[$child->getId()] > 0) {
return true;
}
}
}
return false;
} elseif ($item->getParentItem()) {
$parent = $item->getParentItem();
if (empty($items)) {
return $parent->getQtyToShip() > 0;
} else {
return isset($items[$parent->getId()]) && $items[$parent->getId()] > 0;
}
}
} else {
return $item->getQtyToShip() > 0;
}
}
示例2: shipOrder
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return void
*/
protected function shipOrder(\Magento\Sales\Model\Order\Item $orderItem)
{
$shipmentLoader = $this->shipmentLoaderFactory->create();
$shipmentData = [$orderItem->getId() => $orderItem->getQtyToShip()];
$shipmentLoader->setOrderId($orderItem->getOrderId());
$shipmentLoader->setShipment($shipmentData);
$shipment = $shipmentLoader->load();
if ($shipment) {
$shipment->register();
$shipment->getOrder()->setIsInProcess(true);
$shipmentTransaction = $this->transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
$shipmentTransaction->save();
}
}