Question

The method responsible for reordering is Mage_Sales_Model_Order::_canReorder(). The method _canReorder is called by Mage_Sales_Model_Order::canReorder(). This is actually called to see if you can reorder. I understood that part.

I know that the reorder button doesn't show up when an item is out of stock. How can I make ignore this condition and allow customer to reorder by excluding the out of stock item?

The _canReorder function looks like this:

 protected function _canReorder($ignoreSalable = false)
{
    if ($this->canUnhold() || $this->isPaymentReview()) {
        return false;
    }

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

    $products = [];
    $itemsCollection = $this->getItemsCollection();
    foreach ($itemsCollection as $item) {
        $products[] = $item->getProductId();
    }

    if (!empty($products)) {
        $productsCollection = $this->productListFactory->create()
            ->setStoreId($this->getStoreId())
            ->addIdFilter($products)
            ->addAttributeToSelect('status')
            ->load();

        foreach ($itemsCollection as $item) {
            $product = $productsCollection->getItemById($item->getProductId());
            if (!$product) {
                return false;
            }
            if (!$ignoreSalable && !$product->isSalable()) {
                return false;
            }
        }
    }

    return true;
}

Where is the part that detects "out of stock" item and how can I add logic to exclude out of stock item from reordering cart?

I'm new to Magento, so any help would be appreciated. Thank you.

Était-ce utile?

La solution

From the above code, that things check using this code.

if (!$ignoreSalable && !$product->isSalable()) {
                return false;
}

Autres conseils

isSalable will always going to check the stock availability of the product. What you can actually do is. Override template files vendor/magento/module-sales/view/frontend/templates/order/recent.phtml vendor/magento/module-sales/view/frontend/templates/order/history.phtml

Comment out the canReorder check in those files.

<?php //if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?> ...

<?php //endif ?>

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top