Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento - Implementing order limits based on custom criterias
    primarykey
    data
    text
    <p>I'd like to implement a global order limit on certain products. The point of this is that I want to enable backorders on certain products and define several date periods where there are limits to how many of these individual products that may be ordered.</p> <p>Currently my custom model is loaded with the relevant information for the chosen date period and attached to the product models when they are loaded as <code>$product-&gt;setMyModel(...)</code> on these events:</p> <ul> <li><code>catalog_product_load_after</code></li> <li><code>catalog_product_collection_load_after</code></li> <li><code>sales_quote_item_collection_products_after_load</code></li> </ul> <p>Accessing my model with data for a specific product is as simple as calling <code>$product-&gt;getMyModel()</code>, which I hence will refer to as simply <em>my model</em>.</p> <p><strong>This is what I want to do:</strong></p> <p><strong>1.</strong> Whenever a product is added to a cart/quote, or placed in an order, I want to do something like this (pseudocode):</p> <pre><code>// Somehow get $product and $requestedQty (most likely from an event) $myModel = $product-&gt;getMyModel(); if($myModel-&gt;applyOrderLimit()) { // ($orderedQty + $requestedQty) &lt;= $orderLimit if($myModel-&gt;isRequestedQtyAvailable($requestedQty)) { // Issue an error and prevent the item from being ordered return; } // $orderedQty += $requestedQty $myModel-&gt;addToQtyOrdered($requestedQty); } // Continue Magentos default behaviour </code></pre> <p><strong>1.1.</strong> I suspect that <code>Mage_CatalogInventory_Item::checkQuoteItemQty()</code> should be overriden to capture the <code>$requestedQty</code> here.</p> <p><strong>2.</strong> Update <code>$myModel::ordered_qty</code> whenever an order is cancelled, refunded or such.</p> <p>I guess the real question is where do I run this code, and is there anything more to implementing such an order limit and keeping track of the qty's than I have realized?</p> <p>To me, this seem like quite a complex task. Which is why I need assistance from more experienced Magento developers!</p> <p><em>Note: I couldnt figure out how to mix numbered lists and code blocks, but I hope its readable enough</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload