How to create a reorder button outside the client panel?
-
05-10-2020 - |
سؤال
How can I create a Reorder button outside the client panel (/customer/account/
)?
I tried to copy and paste the code on my home page
but got the error:
Fatal error: Call to a member function getStore() on a non-object in /var/www/html/app/code/core/Mage/Sales/Helper/Reorder.php on line 57
The code that I copied is this one:
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
<?php endif ?>
This page is only loaded if the user is logged in.
Thanks :)
المحلول
Place below code in your template file
<?php
if (Mage::app()->isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
$_customer=Mage::getSingleton('customer/session')->getCustomer();
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $_customer->getId())
->addAttributeToSort('created_at', 'DESC')
->setPageSize(1);
if($orders)
{?>
<a href="<?php echo $this->getUrl('sales/order/reorder', array('order_id' => $orders->getFirstItem()->getId())) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
<?php }
}
} ?>
لا تنتمي إلى magento.stackexchange