0

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.

0

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

if (!$ignoreSalable && !$product->isSalable()) {
                return false;
}
  • so "isSalable" checks product’s “status”, stock availability. In my case, if for example, I would like the reorder button to always appear, so the customer can just click the "reorder" button. Right now, what it is doing is that, if an order history X has n items. if 1 item out of the n items is out-of-stock, the reorder button doesn't appear. I'm wondering how can I make the reorder button to always appear, so when a customer clicks on the reorder button, it will create the new shopping cart with the items that are available. Can I just remove the "isSalable()" from this if statement? – Magento_learner Sep 1 '20 at 1:51
  • And would it affect how the code works? Thanks in advance. I'm still new to Magento, so any help will be appreciated. – Magento_learner Sep 1 '20 at 1:52
  • Yes, it affect the magento default functionality, because your requirement is to modify that one. – Dhiren Vasoya Sep 1 '20 at 4:41
  • How would it affect it? If I remove isSalable, the code won't check the product status anymore and will always make the "reorder button" to always show up? – Magento_learner Sep 1 '20 at 15:34
0

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 ?>

  • If I comment that out, how can it successfully create a new order and ignore the out of stock items? – Magento_learner Aug 20 '20 at 14:41
  • Don't comment the whole section, comment only if statement. Let the button be shown regardless if the product in the order is saleable or not. – Arbab Ahmed Aug 21 '20 at 10:00
  • how would it handle the out-of-stock item if I comment that if statement? – Magento_learner Aug 31 '20 at 3:29
  • Backend code will automatically handle that. – Arbab Ahmed Sep 1 '20 at 5:32

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.