From e2857d3749befffdc780351509e3b4627e669121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Szyma=C5=84ski?= Date: Sun, 20 Sep 2015 20:01:53 +0200 Subject: [PATCH] Initial release --- pkg/limit_items_quantity_in_cart-1.0.0.tgz | Bin 0 -> 2915 bytes pkg/limit_items_quantity_in_cart.xml | 95 ++++++++++++++++++ .../Eeree/OneProductAtATime/Helper/Data.php | 10 ++ .../OneProductAtATime/Model/Observer.php | 86 ++++++++++++++++ .../Eeree/OneProductAtATime/etc/config.xml | 46 +++++++++ .../Eeree/OneProductAtATime/etc/system.xml | 34 +++++++ .../etc/modules/Eeree_OneProductAtATime.xml | 9 ++ .../locale/en_US/Eeree_OneProductAtATime.csv | 7 ++ .../locale/pl_PL/Eeree_OneProductAtATime.csv | 3 + 9 files changed, 290 insertions(+) create mode 100644 pkg/limit_items_quantity_in_cart-1.0.0.tgz create mode 100644 pkg/limit_items_quantity_in_cart.xml create mode 100644 src/app/code/community/Eeree/OneProductAtATime/Helper/Data.php create mode 100644 src/app/code/community/Eeree/OneProductAtATime/Model/Observer.php create mode 100644 src/app/code/community/Eeree/OneProductAtATime/etc/config.xml create mode 100644 src/app/code/community/Eeree/OneProductAtATime/etc/system.xml create mode 100644 src/app/etc/modules/Eeree_OneProductAtATime.xml create mode 100644 src/app/locale/en_US/Eeree_OneProductAtATime.csv create mode 100644 src/app/locale/pl_PL/Eeree_OneProductAtATime.csv diff --git a/pkg/limit_items_quantity_in_cart-1.0.0.tgz b/pkg/limit_items_quantity_in_cart-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..48c1356f791554000da824b4b808563f657748e3 GIT binary patch literal 2915 zcmV-p3!L;HiwFP!000021MFN|kK4Kt-e&{;4}_6()*B?&&9dx0TAc(rDY|IVBu&zT zJ{gomua%W0N1}Gudytm`MSsIVe@0*X*5rS6NL?&nXPQgKtwZ!3Y$Zt3t4r$}@ zSUR|8l4aS@b^cc|bh-RDrvpXR4MR7Sj?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P( zPggsGo~sjCb%^33ViAKA?%%Se|f z_R*9$mo%*<&4{Z3L%t}Auu+g8L4pJc5+q2FAVGoz2@)hokRU;V1PKzf$Min{00960 N0{{^Q( + rT64vjQDXbaIYSt5 + limit_items_quantity_in_cart + community + + 2 + + Magento module, that allows administrators to limit product quantity in cart, limit number of different products added to cart or limit number of items added per product. + Magento module, that allows administrators to limit product quantity in cart, limit number of different products added to cart or limit number of items added per product. + Massachusetts Institute of Technology License (MITL) + + 1.0.0 + stable + Initial release + + + Kamil Szymanski + + + eeree + + + kamilszymanski@gmail.com + + + 5.3.0 + 7.0.0 + + + + + + + + + + + + + + + + + + + + + Core + + + + + + + + + + + + magelocal + magecommunity + mageetc + magelocale + magelocale + + + + Eeree/OneProductAtATime + modules/Eeree_OneProductAtATime.xml + en_US/Eeree_OneProductAtATime.csv + pl_PL/Eeree_OneProductAtATime.csv + + + file + dir + file + file + file + + + + + + + + + + + + + + + + + diff --git a/src/app/code/community/Eeree/OneProductAtATime/Helper/Data.php b/src/app/code/community/Eeree/OneProductAtATime/Helper/Data.php new file mode 100644 index 0000000..d28bc6f --- /dev/null +++ b/src/app/code/community/Eeree/OneProductAtATime/Helper/Data.php @@ -0,0 +1,10 @@ +_checkTotalItemQuantityInCart(); + $this->_checkQuantityOfProductsInCart(); + $this->_checkItemsLimitPerProduct($observer); + } + + /** + * @param Varien_Event_Observer $observer + * @throws Mage_Core_Exception + */ + protected function _checkItemsLimitPerProduct(Varien_Event_Observer $observer) { + $maxItemsPerProduct = Mage::getStoreConfig('checkout/options/max_per_product_cart_qty'); + /** @noinspection PhpUndefinedMethodInspection */ + $productId = $observer->getProduct()->getEntityId(); + /** @var Mage_Sales_Model_Quote_Item $quoteItem */ + foreach ($this->_getQuoteItems() as $quoteItem) { + if ($quoteItem->getProductId() === $productId && $quoteItem->getQty() > $maxItemsPerProduct) { + Mage::throwException(Mage::helper('eeree_oneproductatatime')->__('You can not add any more products of this type to your cart. Max of %d has been reached', $maxItemsPerProduct)); + } + } + } + + /** + * @throws Mage_Core_Exception + */ + protected function _checkQuantityOfProductsInCart() { + $maxProductsPerCart = Mage::getStoreConfig('checkout/options/max_total_products_cart_qty'); + if ($maxProductsPerCart && count($this->_getQuoteItems()) > $maxProductsPerCart) { + Mage::throwException(Mage::helper('eeree_oneproductatatime')->__('You can not add any more products to your cart. Maximum quantity of unique products equals to %d', $maxProductsPerCart)); + } + + } + + /** + * @throws Mage_Core_Exception + */ + protected function _checkTotalItemQuantityInCart() { + $maxItemsPerCart = Mage::getStoreConfig('checkout/options/max_total_cart_qty'); + if ($maxItemsPerCart && $maxItemsPerCart > $this->_getQuote()->getItemsCount()) { + Mage::throwException(Mage::helper('eeree_oneproductatatime')->__('You can not add any more items to you cart. Max of %d has been reached', $maxItemsPerCart)); + } + } + + /** + * @return Mage_Sales_Model_Quote + */ + protected function _getQuote() { + if ($this->quote === null) { + $this->quote = Mage::getSingleton('checkout/session')->getQuote(); + } + + return $this->quote; + } + + /** + * @return array + */ + protected function _getQuoteItems() { + if ($this->quoteItems === null) { + $this->quoteItems = $this->_getQuote()->getAllItems(); + } + + return $this->quoteItems; + } +} diff --git a/src/app/code/community/Eeree/OneProductAtATime/etc/config.xml b/src/app/code/community/Eeree/OneProductAtATime/etc/config.xml new file mode 100644 index 0000000..0001e9c --- /dev/null +++ b/src/app/code/community/Eeree/OneProductAtATime/etc/config.xml @@ -0,0 +1,46 @@ + + + + + 1.0.0 + + + + + + Eeree_OneProductAtATime_Model + eeree_oneproductatatime_resource + + + Eeree_OneProductAtATime_Model_Resource + + + + + Eeree_OneProductAtATime_Helper + + + + + + + Eeree_OneProductAtATime.csv + + + + + + + + + + + singleton + Eeree_OneProductAtATime_Model_Observer + catalogProductTypePrepareFullOptions + + + + + + \ No newline at end of file diff --git a/src/app/code/community/Eeree/OneProductAtATime/etc/system.xml b/src/app/code/community/Eeree/OneProductAtATime/etc/system.xml new file mode 100644 index 0000000..a3ce64c --- /dev/null +++ b/src/app/code/community/Eeree/OneProductAtATime/etc/system.xml @@ -0,0 +1,34 @@ + + + + + + + + + + text + 100 + 1 + 0 to disable + + + + text + 100 + 1 + 0 to disable + + + + text + 100 + 1 + 0 to disable + + + + + + + \ No newline at end of file diff --git a/src/app/etc/modules/Eeree_OneProductAtATime.xml b/src/app/etc/modules/Eeree_OneProductAtATime.xml new file mode 100644 index 0000000..59723c2 --- /dev/null +++ b/src/app/etc/modules/Eeree_OneProductAtATime.xml @@ -0,0 +1,9 @@ + + + + + true + community + + + \ No newline at end of file diff --git a/src/app/locale/en_US/Eeree_OneProductAtATime.csv b/src/app/locale/en_US/Eeree_OneProductAtATime.csv new file mode 100644 index 0000000..857ce04 --- /dev/null +++ b/src/app/locale/en_US/Eeree_OneProductAtATime.csv @@ -0,0 +1,7 @@ +"Maximum Quantity of Items per Product in Cart","Maximum Quantity of Items per Product in Cart" +"Maximum Number of Unique Products Allowed in Cart","Maximum Number of Unique Products Allowed in Cart" +"Maximum Quantity Allowed in Cart (total)","Maximum Quantity Allowed in Cart (total)" +"You can not add any more items to you cart. Max of %d has been reached","You can not add any more items to you cart. Max of %d has been reached" +"You can not add any more products of this type to your cart. Max of %d has been reached","You can not add any more products of this type to your cart. Max of %d has been reached" +"You can not add any more products to your cart. Maximum quantity of unique products equals to %d",""You can not add any more products to your cart. Maximum quantity of unique products equals to %d" +"0 to disable","0 to disable" diff --git a/src/app/locale/pl_PL/Eeree_OneProductAtATime.csv b/src/app/locale/pl_PL/Eeree_OneProductAtATime.csv new file mode 100644 index 0000000..3959541 --- /dev/null +++ b/src/app/locale/pl_PL/Eeree_OneProductAtATime.csv @@ -0,0 +1,3 @@ +"Maximum Quantity Allowed in Cart (total qty)","Maksymalna ilość produktów w koszyku" +"You can only buy one product at a time.","W koszyku może znajdować się tylko jeden rodzaj produktu." +"0 equals to unlimited","Wpisz 0, aby wyłączyć opcję"