سؤال

I have an order id, i need to check if the order can be shipped or already has shipment and but one of the order item has not been shipped or returned, roughly it will look like this:

$orderId = 6;
//get Order From order Id
$order = $this->loadOrder($orderId); 
//check if this order has shipment or not
$hasShipment = $this->checkHasShipment($order);
//if the order has shipment it will check, if all the order item has been shipped
if($hasShipment){
 $allShipped = $this->checkAllHasBeenShipped($order);
}
هل كانت مفيدة؟

المحلول

I think you should change to $oder->canShip() to check if $order can be shipped.

Because Core Magento already do that for us, look at this method:

/**
 * Retrieve order shipment availability
 *
 * @return bool
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 */
public function canShip()
{
    if ($this->canUnhold() || $this->isPaymentReview()) {
        return false;
    }

    if ($this->getIsVirtual() || $this->isCanceled()) {
        return false;
    }

    if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) {
        return false;
    }

    foreach ($this->getAllItems() as $item) {
        if ($item->getQtyToShip() > 0 && !$item->getIsVirtual() && !$item->getLockedDoShip()) {
            return true;
        }
    }
    return false;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top