Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
eeree committed Sep 20, 2015
1 parent 7db8f13 commit e2857d3
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 0 deletions.
Binary file added pkg/limit_items_quantity_in_cart-1.0.0.tgz
Binary file not shown.
95 changes: 95 additions & 0 deletions pkg/limit_items_quantity_in_cart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<_>
<form_key>rT64vjQDXbaIYSt5</form_key>
<name>limit_items_quantity_in_cart</name>
<channel>community</channel>
<version_ids>
<version_ids>2</version_ids>
</version_ids>
<summary>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.</summary>
<description>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.</description>
<license>Massachusetts Institute of Technology License (MITL)</license>
<license_uri/>
<version>1.0.0</version>
<stability>stable</stability>
<notes>Initial release</notes>
<authors>
<name>
<name>Kamil Szymanski</name>
</name>
<user>
<user>eeree</user>
</user>
<email>
<email>[email protected]</email>
</email>
</authors>
<depends_php_min>5.3.0</depends_php_min>
<depends_php_max>7.0.0</depends_php_max>
<depends>
<package>
<name>
<name/>
</name>
<channel>
<channel/>
</channel>
<min>
<min/>
</min>
<max>
<max/>
</max>
<files>
<files> </files>
</files>
</package>
<extension>
<name>
<name>Core</name>
</name>
<min>
<min/>
</min>
<max>
<max/>
</max>
</extension>
</depends>
<contents>
<target>
<target>magelocal</target>
<target>magecommunity</target>
<target>mageetc</target>
<target>magelocale</target>
<target>magelocale</target>
</target>
<path>
<path/>
<path>Eeree/OneProductAtATime</path>
<path>modules/Eeree_OneProductAtATime.xml</path>
<path>en_US/Eeree_OneProductAtATime.csv</path>
<path>pl_PL/Eeree_OneProductAtATime.csv</path>
</path>
<type>
<type>file</type>
<type>dir</type>
<type>file</type>
<type>file</type>
<type>file</type>
</type>
<include>
<include/>
<include/>
<include/>
<include/>
<include/>
</include>
<ignore>
<ignore/>
<ignore/>
<ignore/>
<ignore/>
<ignore/>
</ignore>
</contents>
</_>
10 changes: 10 additions & 0 deletions src/app/code/community/Eeree/OneProductAtATime/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: Kamil
* Date: 2015-09-20
* Time: 00:42
*/
class Eeree_OneProductAtATime_Helper_Data extends Mage_Core_Helper_Abstract {

}
86 changes: 86 additions & 0 deletions src/app/code/community/Eeree/OneProductAtATime/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* Class Eeree_OneProductAtATime_Model_Observer
*/
class Eeree_OneProductAtATime_Model_Observer extends Varien_Event_Observer
{
/**
* @var Mage_Sales_Model_Quote
*/
protected $quote;

/**
* @var array
*/
protected $quoteItems;

/**
* @param Varien_Event_Observer $observer
* @throws Mage_Core_Exception
*/
public function catalogProductTypePrepareFullOptions(Varien_Event_Observer $observer) {
$this->_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;
}
}
46 changes: 46 additions & 0 deletions src/app/code/community/Eeree/OneProductAtATime/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<config>
<modules>
<Eeree_OneProductAtATime>
<version>1.0.0</version>
</Eeree_OneProductAtATime>
</modules>
<global>
<models>
<eeree_oneproductatatime>
<class>Eeree_OneProductAtATime_Model</class>
<resourceModel>eeree_oneproductatatime_resource</resourceModel>
</eeree_oneproductatatime>
<eeree_oneproductatatime_resource>
<class>Eeree_OneProductAtATime_Model_Resource</class>
</eeree_oneproductatatime_resource>
</models>
<helpers>
<eeree_oneproductatatime>
<class>Eeree_OneProductAtATime_Helper</class>
</eeree_oneproductatatime>
</helpers>
<translate>
<modules>
<eeree_oneproductatatime>
<files>
<default>Eeree_OneProductAtATime.csv</default>
</files>
</eeree_oneproductatatime>
</modules>
</translate>
</global>
<frontend>
<events>
<catalog_product_type_prepare_full_options>
<observers>
<eeree_oneproductatatime>
<type>singleton</type>
<class>Eeree_OneProductAtATime_Model_Observer</class>
<method>catalogProductTypePrepareFullOptions</method>
</eeree_oneproductatatime>
</observers>
</catalog_product_type_prepare_full_options>
</events>
</frontend>
</config>
34 changes: 34 additions & 0 deletions src/app/code/community/Eeree/OneProductAtATime/etc/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<config>
<sections>
<checkout>
<groups>
<options>
<fields>
<max_per_product_cart_qty translate="label">
<label>Maximum Quantity of Items per Product in Cart</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<comment>0 to disable</comment>
</max_per_product_cart_qty>
<max_total_products_cart_qty translate="label">
<label>Maximum Number of Unique Products Allowed in Cart</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<comment>0 to disable</comment>
</max_total_products_cart_qty>
<max_total_cart_qty translate="label">
<label>Maximum Quantity Allowed in Cart (total)</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<comment>0 to disable</comment>
</max_total_cart_qty>
</fields>
</options>
</groups>
</checkout>
</sections>
</config>
9 changes: 9 additions & 0 deletions src/app/etc/modules/Eeree_OneProductAtATime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config>
<modules>
<Eeree_OneProductAtATime>
<active>true</active>
<codePool>community</codePool>
</Eeree_OneProductAtATime>
</modules>
</config>
7 changes: 7 additions & 0 deletions src/app/locale/en_US/Eeree_OneProductAtATime.csv
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions src/app/locale/pl_PL/Eeree_OneProductAtATime.csv
Original file line number Diff line number Diff line change
@@ -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ę"

0 comments on commit e2857d3

Please sign in to comment.