I’m trying to put qty to 0 if qty < 0, but it's not working for me i all time have qty on minus
my code don’t working for me
public function salesOrderSaveAfter($event)
{
$order = $event->getOrder();
$orderIncrementId = $order->getIncrementId();
foreach ($order->getAllVisibleItems() as $item) {
$oldQty = (int)$item->getProduct()->getStockItem()->getQty();
$qtyOrdered = (int)$item->getQtyOrdered();
$differenceQty = $oldQty - $qtyOrdered;
}
//increase the price by 25% AND check for fires twice
if ($differenceQty < 0) {
$product_model = Mage::getModel('catalog/product')->load($item->getProductId());
$price = $product_model->getPrice();
$newPrice = $price + (($price * 25) / 100);
$product_model->setPrice($newPrice);
if ($product_model->getStockItem()->getBackorders() == "2") {
$product_model->setStockData(array(
'use_config_manage_stock' => 1,
'manage_stock' => 1,
'is_in_stock' => 1,
//'qty' => 0 don't working too
)
);
$product_model->setQty(0);
}
$product_model->save();
}
}
I need when the quantity is less 0, for example -3, set quantity to 0