您需要为此任务开发扩展。为事件 sales_order_save_after 创建一个观察者并检查数量就足够了。如果为 0,您可以禁用您的产品。
好吧,我会告诉你怎么做。创建以下文件并清除缓存以使其工作(代码未经测试,但应该可以工作)。
/app/code/local/Sebi/DeactivateOnOutOfStock/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sebi_DeactivateOnOutOfStock>
<version>0.1.0</version>
</Sebi_DeactivateOnOutOfStock>
</modules>
<frontend>
<events>
<sales_order_save_after>
<observers>
<deactivateonoutofstock>
<type>singleton</type>
<class>Sebi_DeactivateOnOutOfStock_Model_Observer</class>
<method>salesOrderSaveAfter</method>
</deactivateonoutofstock>
</observers>
</sales_order_save_after>
</events>
<routers>
<Sebi_DeactivateOnOutOfStock>
<use>standard</use>
<args>
<module>Sebi_DeactivateOnOutOfStock</module>
<frontName>DeactivateOnOutOfStock</frontName>
</args>
</Sebi_DeactivateOnOutOfStock>
</routers>
</frontend>
</config>
/app/code/local/Sebi/DeactivateOnOutOfStock/Model/Observer.php
<?php
class Sebi_DeactivateOnOutOfStock_Model_Observer
{
public function salesOrderSaveAfter($observer)
{
$storeId = 0; //the admin store view, change this if you want to disable only for the store view from which the order came
$order= $observer->getEvent()->getOrder();
foreach ($order->getItemsCollection() as $item) {
$stockQty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($item->getProductId())->getQty();
if ($stockQty == 0) {
Mage::getModel('catalog/product_status')->updateProductStatus($item->getProductId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
}
}
}
}
/app/etc/modules/Sebi_DeactivateOnOutOfStock.xml
<?xml version="1.0"?>
<config>
<modules>
<Sebi_DeactivateOnOutOfStock>
<active>true</active>
<codePool>local</codePool>
</Sebi_DeactivateOnOutOfStock>
</modules>
</config>
祝你好运!不要忘记刷新缓存!
编辑:现在看到你的编辑。售罄时,我不会从客户的购物车中删除商品,因为他们会想到错误并尝试在您的商店中找到它。但他们不能。这将非常令人沮丧。如果他们尝试订购并且在订购时产品已售罄,Magento 会通知他们该产品不再有库存。这必须足够了。