8

Is there any good modules out there that can handle this? Or would this be a custom event / observer that needs to be written?

Here's an image on a non magento site that shows specifically what i'm looking for.

enter image description here

Magento 2.2.3 EE

This needs to work with the Magento commerce b2b module. So everyone in a group/company would be limited. If there was 4 people in the group but one person purchased the max amount then the other 3 would not be allowed to purchase any. This makes it increasingly more complex and difficult logic.

2

You need write your custom module and you have to use this event (sales_quote_item_qty_set_after).

in this event you need to - check current logged user and get all items that the customer purchanesed during current month. - check the QTY of your product, and if the qty is excedded the maximum qty, you need to throw expection

throw new \Magento\Framework\Exception\CouldNotSaveException( __('The most you may purchase is %1.',$_qty));

you can also add message to the item itslef

$quoteItem->getQuote()->addErrorInfo(
        'stock',
        'cataloginventory',
        \Magento\CatalogInventory\Helper\Data::ERROR_QTY,
        __('Please correct the quantity for some products.')
        );

where the $quoteItem coming from this code

$quoteItem = $observer->getEvent()->getItem();

I had before a similarlogic and this work for me

  • Thanks for the response, I forgot to mention this needs to work with the Magento commerce b2b module. So everyone in a group/company would be limited. If there was 4 people in the group but one person purchased the max amount then the other 3 would not be allowed to purchase any. This makes it increasingly more complex and difficult logic. – Supplement Apr 24 '18 at 15:28
  • I believe that you can manage it in this event but you need do check the customer company then you get all items qty for all 4 people (as in your example) – WISAM HAKIM Apr 24 '18 at 17:12
  • Any more updates @WISAMHAKIM, i'm very interested. – getData Apr 27 '18 at 14:28
  • hello @getData, did you try the logic in the second comment ? – WISAM HAKIM Apr 27 '18 at 14:35
  • @WISAMHAKIM what should be the files the above logic is placed in? – getData Apr 27 '18 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.