I making observer, that detects when someone reorders a discontinued product and should replace that product with a new product.
My question is: How do I retrieve a product object with a specific SKU? For example I want to retrieve the product with the SKU D1105
and add that to the cart using $observer->getEvent()->setProduct( $myDD1105Product );
.
I need to know, how to retrieve a product with the SKU D1105
and add it to the cart. Any advice would be greatly appreciated.
<?php
class MHT_Reorder_Model_Observer
{
public function onReorder(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$product = $event->getProduct();
$replacementSku = 'D1105';
$blackListSKUs = ['D1100', 'D1101'];
foreach ($blackListSKUs as $blacklistSku) {
// if product SKU does not equal $blacklistSku: continue iterating
if (strcasecmp($product->getSku(), $blacklistSku) != 0)
continue;
// How do I get the product from Mage/database that has the sku D1105?
$event->setProduct()
break;
}
}
}