I would like to implement a global order limit for some products. The fact is that I want to include backups for certain products and define several periods of dates when there are restrictions on the number of these individual products that can be ordered.
Currently, my user model is loaded with relevant information for a selected period of time and attached to product models when they are loaded as $product->setMyModel(...) into these events:
catalog_product_load_aftercatalog_product_collection_load_aftersales_quote_item_collection_products_after_load
Accessing my model with data for a specific product is as simple as calling $product->getMyModel() , which I will therefore simply call my model.
This is what I want to do:
1. Whenever a product is added to the cart / quote or placed in order, I want to do something like this (pseudocode):
// Somehow get $product and $requestedQty (most likely from an event) $myModel = $product->getMyModel(); if($myModel->applyOrderLimit()) { // ($orderedQty + $requestedQty) <= $orderLimit if($myModel->isRequestedQtyAvailable($requestedQty)) { // Issue an error and prevent the item from being ordered return; } // $orderedQty += $requestedQty $myModel->addToQtyOrdered($requestedQty); } // Continue Magentos default behaviour
1.1. I suspect that Mage_CatalogInventory_Item::checkQuoteItemQty() should be overridden to capture $requestedQty here.
2. Update $myModel::ordered_qty when the order is canceled, returned, or such.
I guess the real question is where do I run this code, and is there anything else to implement such an order limitation and tracking quantity than I understood?
For me this seems like a pretty daunting task. That's why I need help from more experienced Magento developers!
Note. I couldn't figure out how to mix numbered lists and blocks of code, but I hope its readable enough
source share