Version Notes
Initial release
Download this release
Release Info
Developer | Javier Villanueva |
Extension | minorderqty |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
app/code/community/Jvs/MinTotalQty/Helper/Data.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MinTotalQty data helper
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_MinTotalQty
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_MinTotalQty_Helper_Data extends Mage_CatalogInventory_Helper_Minsaleqty
|
10 |
+
{
|
11 |
+
const XML_PATH_MIN_TOTAL_QTY = 'cataloginventory/options/min_total_qty';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Retrieve min_total_qty value from config
|
15 |
+
*
|
16 |
+
* @param int $customerGroupId
|
17 |
+
* @param mixed $store
|
18 |
+
* @return float|null
|
19 |
+
*/
|
20 |
+
public function getConfigValue($customerGroupId, $store = null)
|
21 |
+
{
|
22 |
+
$value = Mage::getStoreConfig(self::XML_PATH_MIN_TOTAL_QTY, $store);
|
23 |
+
$value = $this->_unserializeValue($value);
|
24 |
+
if ($this->_isEncodedArrayFieldValue($value)) {
|
25 |
+
$value = $this->_decodeArrayFieldValue($value);
|
26 |
+
}
|
27 |
+
$result = null;
|
28 |
+
foreach ($value as $groupId => $qty) {
|
29 |
+
if ($groupId == $customerGroupId) {
|
30 |
+
$result = $qty;
|
31 |
+
break;
|
32 |
+
} else if ($groupId == Mage_Customer_Model_Group::CUST_GROUP_ALL) {
|
33 |
+
$result = $qty;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
return $this->_fixQty($result);
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Check if quote meets the minimun quantity
|
41 |
+
* of total items for a specific customer
|
42 |
+
*
|
43 |
+
* @todo Change to more meaningful name
|
44 |
+
*
|
45 |
+
* @param Mage_Sales_Model_Quote $quote
|
46 |
+
* @param Mage_Customer_Model_Customer $customer
|
47 |
+
* @return int|false
|
48 |
+
*/
|
49 |
+
public function minimunOrderQty(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Customer $customer)
|
50 |
+
{
|
51 |
+
$minQtyForCustomer = $this->getConfigValue($customer->getGroupId());
|
52 |
+
|
53 |
+
if ($quote->getItemsQty() < $minQtyForCustomer && $quote->getItemsQty() !== 0) {
|
54 |
+
return $minQtyForCustomer;
|
55 |
+
}
|
56 |
+
|
57 |
+
return false;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Check if current page is shopping cart
|
62 |
+
*
|
63 |
+
* @return boolean
|
64 |
+
*/
|
65 |
+
public function isCartPage()
|
66 |
+
{
|
67 |
+
$frontController = Mage::app()->getFrontController();
|
68 |
+
|
69 |
+
return ($frontController->getAction()->getFullActionName() === 'checkout_cart_index');
|
70 |
+
}
|
71 |
+
}
|
app/code/community/Jvs/MinTotalQty/Model/Observer.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MinTotalQty observer model
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_MinTotalQty
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_MinTotalQty_Model_Observer
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Check minimun order totals
|
13 |
+
*
|
14 |
+
* @param Varien_Event_Observer $observer
|
15 |
+
* @return void
|
16 |
+
*/
|
17 |
+
public function checkTotalQtyBeforeCheckout(Varien_Event_Observer $observer)
|
18 |
+
{
|
19 |
+
$quote = $observer->getDataObject();
|
20 |
+
$customer = Mage::helper('customer')->getCustomer();
|
21 |
+
|
22 |
+
// If the minimun total quantity is not met
|
23 |
+
// redirect to cart page with error message
|
24 |
+
if ($minQty = Mage::helper('jvs_mintotalqty')->minimunOrderQty($quote, $customer)) {
|
25 |
+
Mage::getSingleton('checkout/session')->addUniqueMessages(
|
26 |
+
Mage::getSingleton('core/message')
|
27 |
+
->error(
|
28 |
+
Mage::helper('cataloginventory')
|
29 |
+
->__(
|
30 |
+
'The minimum quantity allowed for purchase is %s.',
|
31 |
+
$minQty
|
32 |
+
)
|
33 |
+
)
|
34 |
+
);
|
35 |
+
|
36 |
+
// Check if we are not already on the cart page
|
37 |
+
if (!Mage::helper('jvs_mintotalqty')->isCartPage()) {
|
38 |
+
Mage::app()->getFrontController()->getResponse()
|
39 |
+
->setRedirect(Mage::getUrl('checkout/cart'));
|
40 |
+
|
41 |
+
Mage::app()->getRequest()->setDispatched(true);
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Jvs/MinTotalQty/etc/config.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Jvs_MinTotalQty>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Jvs_MinTotalQty>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<jvs_mintotalqty>
|
11 |
+
<class>Jvs_MinTotalQty_Model</class>
|
12 |
+
</jvs_mintotalqty>
|
13 |
+
</models>
|
14 |
+
<helpers>
|
15 |
+
<jvs_mintotalqty>
|
16 |
+
<class>Jvs_MinTotalQty_Helper</class>
|
17 |
+
</jvs_mintotalqty>
|
18 |
+
</helpers>
|
19 |
+
</global>
|
20 |
+
<frontend>
|
21 |
+
<events>
|
22 |
+
<sales_quote_save_after>
|
23 |
+
<observers>
|
24 |
+
<jvs_mintotalqty_checkqty>
|
25 |
+
<class>jvs_mintotalqty/observer</class>
|
26 |
+
<method>checkTotalQtyBeforeCheckout</method>
|
27 |
+
</jvs_mintotalqty_checkqty>
|
28 |
+
</observers>
|
29 |
+
</sales_quote_save_after>
|
30 |
+
</events>
|
31 |
+
</frontend>
|
32 |
+
</config>
|
app/code/community/Jvs/MinTotalQty/etc/system.xml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<cataloginventory>
|
5 |
+
<groups>
|
6 |
+
<options>
|
7 |
+
<fields>
|
8 |
+
<min_total_qty translate="label">
|
9 |
+
<label>Minimum Qty Allowed in Shopping Cart</label>
|
10 |
+
<frontend_model>cataloginventory/adminhtml_form_field_minsaleqty</frontend_model>
|
11 |
+
<backend_model>cataloginventory/system_config_backend_minsaleqty</backend_model>
|
12 |
+
<sort_order>60</sort_order>
|
13 |
+
<show_in_default>1</show_in_default>
|
14 |
+
<show_in_website>0</show_in_website>
|
15 |
+
<show_in_store>0</show_in_store>
|
16 |
+
</min_total_qty>
|
17 |
+
</fields>
|
18 |
+
</options>
|
19 |
+
</groups>
|
20 |
+
</cataloginventory>
|
21 |
+
</sections>
|
22 |
+
</config>
|
app/etc/modules/Jvs_MinTotalQty.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Jvs_MinTotalQty>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Jvs_MinTotalQty>
|
8 |
+
<depends>
|
9 |
+
<Mage_CatalogInventory/>
|
10 |
+
</depends>
|
11 |
+
</modules>
|
12 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>minorderqty</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="https://opensource.org/licenses/MIT">MIT</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Set minimum total quantities for orders per customer group.</summary>
|
10 |
+
<description>By default Magento lets us set the minimum quantity allowed in the shopping cart for individual items but this extension lets you set a minimum quantity for the whole order.
|
11 |
+

|
12 |
+
This is specially useful if you have, for example, a "Wholesale" customer group and want the minimum number of items in the order for this group to be 12 no matter how many of each individual items the order has.</description>
|
13 |
+
<notes>Initial release</notes>
|
14 |
+
<authors><author><name>Javier Villanueva</name><user>javiervd</user><email>javiervd@gmail.com</email></author></authors>
|
15 |
+
<date>2015-10-04</date>
|
16 |
+
<time>13:17:08</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="Jvs"><dir name="MinTotalQty"><dir name="Helper"><file name="Data.php" hash="cb6ecd90ba3d9ce51bd2de32ced57b31"/></dir><dir name="Model"><file name="Observer.php" hash="580a21556c016797f9b84f9e24c2cef6"/></dir><dir name="etc"><file name="config.xml" hash="2d7a18319bd72b3632e0d920feee231f"/><file name="system.xml" hash="429d4dae5e66a18802f0041676b4a841"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Jvs_MinTotalQty.xml" hash="7f3a3bd895248cadd5ee778d8da4eb92"/></dir></target></contents>
|
18 |
+
<compatible/>
|
19 |
+
<dependencies><required><php><min>5.3.0</min><max>5.6.14</max></php></required></dependencies>
|
20 |
+
</package>
|