I want to rewrite Reorder controller from MagentoSalesControllerAbstractControllerReorder. In di.xml I put
<preference for = "MagentoSalesControllerAbstractControllerReorder" type = "VendorModuleControllerAbstractControllerCustomReorder"/>
And in the /Controller/AbstractController/CustomReorder.php I have:
<?php
namespace VendorModuleControllerAbstractController;
class CustomReorder extends MagentoSalesControllerAbstractControllerReorder
{
/**
* Action for reorder
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
{
$result = $this->orderLoader->load($this->_request);
if ($result instanceof MagentoFrameworkControllerResultInterface) {
return $result;
}
$order = $this->_coreRegistry->registry('current_order');
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
/* @var $cart MagentoCheckoutModelCart */
$cart = $this->_objectManager->get(MagentoCheckoutModelCart::class);
$items = $order->getItemsCollection();
error_log( 'MY STUFF: ' . print_r( "TEST", true ) );
foreach ($items as $item) {
error_log( 'MY STUFF: ' . print_r( "12121", true ) );
try {
$cart->addOrderItem($item);
} catch (MagentoFrameworkExceptionLocalizedException $e) {
if ($this->_objectManager->get(MagentoCheckoutModelSession::class)->getUseNotice(true)) {
$this->messageManager->addNoticeMessage($e->getMessage());
} else {
$this->messageManager->addErrorMessage($e->getMessage());
}
return $resultRedirect->setPath('*/*/history');
} catch (Exception $e) {
$this->messageManager->addExceptionMessage(
$e,
__('We can't add this item to your shopping cart right now.')
);
return $resultRedirect->setPath('checkout/cart');
}
}
$cart->save();
return $resultRedirect->setPath('checkout/cart');
}
}
What I want is to check every item and if the price is 0(I have a module where I can insert a product with price 0 if in the cart is a certain product) to jump over that item when I press Order again from order history from my account. But nothing happen. I put those error_logs but without any results. Do you know what do I do wrong or what do I have to do? If I put in vendor
if($item->getPrice === "0.0000") continue
it’s working.
Thank you!