4

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);
}
2

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.