Gai*_*aia 1 magento e-commerce magento-1.5
我知道我们可以很容易地限制客户可以按订单购买的给定产品的最大数量,但是是否可以(本机或甚至使用插件)限制每个客户的给定产品的最大数量?
我不想使用优惠券或修改代码:它需要在本机或扩展功能的帮助下成为销售价格.
Magento 1.5.1
本机不可能,但您可以创建一个将执行此类限制的模块.
您需要创建一个资源模型,该模型将检索未取消且未退还的具有特定产品ID的产品的订单.实际上它只是一个简单的选择销售/订单和销售/ order_item表.资源模型的方法可能如下所示:
public function getPurchasedProductQty(array $productIds, $customerId)
{
$select = $this->_getReadAdapter()->select();
$select
->from(array('order_item' => $this->getTable('sales/order_item')),
array(
'qty' => new Zend_Db_Expr('order_item.ordered_qty - order_item.canceled_qty - order_item.refunded_qty'),
'product_id'))
// Joining order to retrieve info about item and filter out canceled or refunded orders
->join(array('order' => $this->getTable('sales/order')),
'order.entity_id = order_item.order_id',
array())
// Limit it to the current customer
->where('order.customer_id = ?', $customerId)
// Filter out refunded and canceled orders
->where('order.state NOT IN(?)', array(
Mage_Sales_Model_Order::STATE_CLOSED,
Mage_Sales_Model_Order::STATE_CANCELED
))
// Add Product Id Condition
->where('order_item.product_id IN(?)', $productIds);
return $this->_getReadAdapter()->fetchCol($select);
}
Run Code Online (Sandbox Code Playgroud)然后,当您观察sales_quote_item_collection_products_after_load事件时,您可以放置自定义逻辑,检查将在购物车中使用的产品的限制,并从已加载的集合中删除这些产品.这个逻辑你应该自己实现.