Version Notes
Trigger functionality on checkout pages only instead of when quote is saved to improve performance and compatibility issues with ajax add to cart extensions.
Download this release
Release Info
Developer | Javier Villanueva |
Extension | minorderqty |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 2.0.0
- app/code/community/Jvs/FileAttribute/Block/Element/File.php +104 -0
- app/code/community/Jvs/FileAttribute/Block/Product/View/Attributes.php +56 -0
- app/code/community/Jvs/FileAttribute/Helper/Data.php +12 -0
- app/code/community/Jvs/FileAttribute/Model/Attribute/Backend/File.php +76 -0
- app/code/community/Jvs/FileAttribute/Model/Observer.php +81 -0
- app/code/community/Jvs/FileAttribute/etc/config.xml +71 -0
- app/code/community/Jvs/MinTotalQty/Model/Observer.php +10 -4
- app/code/community/Jvs/MinTotalQty/etc/config.xml +20 -4
- package.xml +5 -5
app/code/community/Jvs/FileAttribute/Block/Element/File.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Frontend model for file upload input type
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_FileAttribute
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_FileAttribute_Block_Element_File extends Varien_Data_Form_Element_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Constructor
|
13 |
+
*
|
14 |
+
* @param array $data
|
15 |
+
*/
|
16 |
+
public function __construct($data)
|
17 |
+
{
|
18 |
+
parent::__construct($data);
|
19 |
+
$this->setType('file');
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Return element html code
|
24 |
+
*
|
25 |
+
* @return string
|
26 |
+
*/
|
27 |
+
public function getElementHtml()
|
28 |
+
{
|
29 |
+
$html = '';
|
30 |
+
|
31 |
+
if ((string)$this->getValue()) {
|
32 |
+
$url = $this->_getUrl();
|
33 |
+
|
34 |
+
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
|
35 |
+
$url = Mage::getBaseUrl('media') . $url;
|
36 |
+
}
|
37 |
+
|
38 |
+
$html = '<a href="' . $url . '"'
|
39 |
+
. ' onclick="popWin(\'' . $url . '\',\'preview\',\'top:0,left:0,width=820,height=600,resizable=yes,scrollbars=yes\'); return false;">'
|
40 |
+
. '<img src="' . Mage::getDesign()->getSkinUrl('images/fam_page_white.gif') . '" id="' . $this->getHtmlId() . '_image" title="' . $this->getValue() . '"'
|
41 |
+
. ' alt="' . $this->getValue() . '" height="16" width="16" class="small-image-preview v-middle" />'
|
42 |
+
. '</a> ';
|
43 |
+
}
|
44 |
+
$this->setClass('input-file');
|
45 |
+
$html .= parent::getElementHtml();
|
46 |
+
$html .= $this->_getDeleteCheckbox();
|
47 |
+
|
48 |
+
return $html;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Return html code of delete checkbox element
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
protected function _getDeleteCheckbox()
|
57 |
+
{
|
58 |
+
$html = '';
|
59 |
+
if ($this->getValue()) {
|
60 |
+
$label = Mage::helper('jvs_fileattribute')->__('Delete File');
|
61 |
+
$html .= '<span class="delete-image">';
|
62 |
+
$html .= '<input type="checkbox"'
|
63 |
+
. ' name="' . parent::getName() . '[delete]" value="1" class="checkbox"'
|
64 |
+
. ' id="' . $this->getHtmlId() . '_delete"' . ($this->getDisabled() ? ' disabled="disabled"': '')
|
65 |
+
. '/>';
|
66 |
+
$html .= '<label for="' . $this->getHtmlId() . '_delete"'
|
67 |
+
. ($this->getDisabled() ? ' class="disabled"' : '') . '> ' . $label . '</label>';
|
68 |
+
$html .= $this->_getHiddenInput();
|
69 |
+
$html .= '</span>';
|
70 |
+
}
|
71 |
+
|
72 |
+
return $html;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Return html code of hidden element
|
77 |
+
*
|
78 |
+
* @return string
|
79 |
+
*/
|
80 |
+
protected function _getHiddenInput()
|
81 |
+
{
|
82 |
+
return '<input type="hidden" name="' . parent::getName() . '[value]" value="' . $this->getValue() . '" />';
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Get image preview url
|
87 |
+
*
|
88 |
+
* @return string
|
89 |
+
*/
|
90 |
+
protected function _getUrl()
|
91 |
+
{
|
92 |
+
return 'catalog/product' . $this->getValue();
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Return name
|
97 |
+
*
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
public function getName()
|
101 |
+
{
|
102 |
+
return $this->getData('name');
|
103 |
+
}
|
104 |
+
}
|
app/code/community/Jvs/FileAttribute/Block/Product/View/Attributes.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product description block
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_FileAttribute
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_FileAttribute_Block_Product_View_Attributes extends Mage_Catalog_Block_Product_View_Attributes
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* $excludeAttr is optional array of attribute codes to
|
13 |
+
* exclude them from additional data array
|
14 |
+
*
|
15 |
+
* @param array $excludeAttr
|
16 |
+
* @return array
|
17 |
+
*/
|
18 |
+
public function getAdditionalData(array $excludeAttr = array())
|
19 |
+
{
|
20 |
+
$data = array();
|
21 |
+
$product = $this->getProduct();
|
22 |
+
$attributes = $product->getAttributes();
|
23 |
+
foreach ($attributes as $attribute) {
|
24 |
+
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
|
25 |
+
$value = $attribute->getFrontend()->getValue($product);
|
26 |
+
|
27 |
+
if (!$product->hasData($attribute->getAttributeCode())) {
|
28 |
+
$value = Mage::helper('catalog')->__('N/A');
|
29 |
+
} elseif ((string)$value == '') {
|
30 |
+
$value = Mage::helper('catalog')->__('No');
|
31 |
+
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
|
32 |
+
$value = Mage::app()->getStore()->convertPrice($value, true);
|
33 |
+
}
|
34 |
+
|
35 |
+
// If 'file upload' input type generate download link
|
36 |
+
if ($attribute->getFrontendInput() == 'jvs_file'
|
37 |
+
&& (string)$value != Mage::helper('catalog')->__('No')
|
38 |
+
&& (string)$value != Mage::helper('catalog')->__('N/A')
|
39 |
+
) {
|
40 |
+
$value = '<a href="' . $this->escapeUrl(Mage::getBaseUrl('media') . 'catalog/product' . $value) . '">';
|
41 |
+
$value .= Mage::helper('jvs_fileattribute')->__('Download');
|
42 |
+
$value .= '</a>';
|
43 |
+
}
|
44 |
+
|
45 |
+
if (is_string($value) && strlen($value)) {
|
46 |
+
$data[$attribute->getAttributeCode()] = array(
|
47 |
+
'label' => $attribute->getStoreLabel(),
|
48 |
+
'value' => $value,
|
49 |
+
'code' => $attribute->getAttributeCode()
|
50 |
+
);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
}
|
54 |
+
return $data;
|
55 |
+
}
|
56 |
+
}
|
app/code/community/Jvs/FileAttribute/Helper/Data.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* FileAttribute data helper
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_FileAttribute
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_FileAttribute_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
+
{
|
11 |
+
|
12 |
+
}
|
app/code/community/Jvs/FileAttribute/Model/Attribute/Backend/File.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Backend model for file upload input type
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_FileAttribute
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_FileAttribute_Model_Attribute_Backend_File
|
10 |
+
extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
|
11 |
+
{
|
12 |
+
/**
|
13 |
+
* After attribute is saved upload file to media
|
14 |
+
* folder and save it to its associated product.
|
15 |
+
*
|
16 |
+
* @param Mage_Catalog_Model_Product $object
|
17 |
+
* @return Jvs_FileAttribute_Model_Attribute_Backend_File
|
18 |
+
*/
|
19 |
+
public function afterSave($object)
|
20 |
+
{
|
21 |
+
$value = $object->getData($this->getAttribute()->getName());
|
22 |
+
|
23 |
+
if (is_array($value) && !empty($value['delete'])) {
|
24 |
+
$object->setData($this->getAttribute()->getName(), '');
|
25 |
+
$this->getAttribute()->getEntity()
|
26 |
+
->saveAttribute($object, $this->getAttribute()->getName());
|
27 |
+
return;
|
28 |
+
}
|
29 |
+
|
30 |
+
try {
|
31 |
+
$uploadedFile = new Varien_Object();
|
32 |
+
$uploadedFile->setData('name', $this->getAttribute()->getName());
|
33 |
+
$uploadedFile->setData(
|
34 |
+
'allowed_extensions',
|
35 |
+
array(
|
36 |
+
'jpg',
|
37 |
+
'jpeg',
|
38 |
+
'gif',
|
39 |
+
'png',
|
40 |
+
'tif',
|
41 |
+
'tiff',
|
42 |
+
'mpg',
|
43 |
+
'mpeg',
|
44 |
+
'mp3',
|
45 |
+
'wav',
|
46 |
+
'pdf',
|
47 |
+
'txt',
|
48 |
+
)
|
49 |
+
);
|
50 |
+
|
51 |
+
Mage::dispatchEvent(
|
52 |
+
'jvs_fileattribute_allowed_extensions',
|
53 |
+
array('file' => $uploadedFile)
|
54 |
+
);
|
55 |
+
|
56 |
+
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
|
57 |
+
$uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions'));
|
58 |
+
$uploader->setAllowRenameFiles(true);
|
59 |
+
$uploader->setFilesDispersion(true);
|
60 |
+
|
61 |
+
$uploader->save(Mage::getBaseDir('media') . '/catalog/product');
|
62 |
+
} catch (Exception $e) {
|
63 |
+
return $this;
|
64 |
+
}
|
65 |
+
|
66 |
+
$fileName = $uploader->getUploadedFileName();
|
67 |
+
|
68 |
+
if ($fileName) {
|
69 |
+
$object->setData($this->getAttribute()->getName(), $fileName);
|
70 |
+
$this->getAttribute()->getEntity()
|
71 |
+
->saveAttribute($object, $this->getAttribute()->getName());
|
72 |
+
}
|
73 |
+
|
74 |
+
return $this;
|
75 |
+
}
|
76 |
+
}
|
app/code/community/Jvs/FileAttribute/Model/Observer.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* FileAttribute observer model
|
4 |
+
*
|
5 |
+
* @category Jvs
|
6 |
+
* @package Jvs_FileAttribute
|
7 |
+
* @author Javier Villanueva <javiervd@gmail.com>
|
8 |
+
*/
|
9 |
+
class Jvs_FileAttribute_Model_Observer
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Add file upload input type to attribute creation dropdown
|
13 |
+
*
|
14 |
+
* @param Varien_Event_Observer $observer
|
15 |
+
*/
|
16 |
+
public function addFileAttributeType(Varien_Event_Observer $observer)
|
17 |
+
{
|
18 |
+
$response = $observer->getEvent()->getResponse();
|
19 |
+
$types = $response->getTypes();
|
20 |
+
$types[] = array(
|
21 |
+
'value' => 'jvs_file',
|
22 |
+
'label' => Mage::helper('jvs_fileattribute')->__('File Upload'),
|
23 |
+
'hide_fields' => array(
|
24 |
+
'is_unique',
|
25 |
+
'is_required',
|
26 |
+
'frontend_class',
|
27 |
+
'is_configurable',
|
28 |
+
'_default_value',
|
29 |
+
|
30 |
+
'is_searchable',
|
31 |
+
'is_visible_in_advanced_search',
|
32 |
+
'is_filterable',
|
33 |
+
'is_filterable_in_search',
|
34 |
+
'is_comparable',
|
35 |
+
'is_used_for_promo_rules',
|
36 |
+
'position',
|
37 |
+
'used_in_product_listing',
|
38 |
+
'used_for_sort_by',
|
39 |
+
)
|
40 |
+
);
|
41 |
+
|
42 |
+
$response->setTypes($types);
|
43 |
+
|
44 |
+
return $this;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Assign backend model to file upload input type
|
49 |
+
*
|
50 |
+
* @param Varien_Event_Observer $observer
|
51 |
+
* @return Jvs_FileAttribute_Model_Observer
|
52 |
+
*/
|
53 |
+
public function assignBackendModelToAttribute(Varien_Event_Observer $observer)
|
54 |
+
{
|
55 |
+
$backendModel = 'jvs_fileattribute/attribute_backend_file';
|
56 |
+
/** @var $object Mage_Eav_Model_Entity_Attribute_Abstract */
|
57 |
+
$object = $observer->getEvent()->getAttribute();
|
58 |
+
|
59 |
+
if ($object->getFrontendInput() == 'jvs_file') {
|
60 |
+
$object->setBackendModel($backendModel);
|
61 |
+
$object->setBackendType('varchar');
|
62 |
+
}
|
63 |
+
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Assign frontend model to file upload input type
|
69 |
+
*
|
70 |
+
* @param Varien_Event_Observer $observer
|
71 |
+
* @return Jvs_FileAttribute_Model_Observer
|
72 |
+
*/
|
73 |
+
public function updateElementTypes(Varien_Event_Observer $observer)
|
74 |
+
{
|
75 |
+
$response = $observer->getEvent()->getResponse();
|
76 |
+
$types = $response->getTypes();
|
77 |
+
$types['jvs_file'] = Mage::getConfig()->getBlockClassName('jvs_fileattribute/element_file');
|
78 |
+
$response->setTypes($types);
|
79 |
+
return $this;
|
80 |
+
}
|
81 |
+
}
|
app/code/community/Jvs/FileAttribute/etc/config.xml
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Jvs_FileAttribute>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Jvs_FileAttribute>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<blocks>
|
10 |
+
<jvs_fileattribute>
|
11 |
+
<class>Jvs_FileAttribute_Block</class>
|
12 |
+
</jvs_fileattribute>
|
13 |
+
<catalog>
|
14 |
+
<rewrite>
|
15 |
+
<product_view_attributes>Jvs_FileAttribute_Block_Product_View_Attributes</product_view_attributes>
|
16 |
+
</rewrite>
|
17 |
+
</catalog>
|
18 |
+
</blocks>
|
19 |
+
<models>
|
20 |
+
<jvs_fileattribute>
|
21 |
+
<class>Jvs_FileAttribute_Model</class>
|
22 |
+
</jvs_fileattribute>
|
23 |
+
</models>
|
24 |
+
<helpers>
|
25 |
+
<jvs_fileattribute>
|
26 |
+
<class>Jvs_FileAttribute_Helper</class>
|
27 |
+
</jvs_fileattribute>
|
28 |
+
</helpers>
|
29 |
+
<events>
|
30 |
+
<catalog_entity_attribute_save_before>
|
31 |
+
<observers>
|
32 |
+
<jvs_fileattribute>
|
33 |
+
<type>model</type>
|
34 |
+
<class>jvs_fileattribute/observer</class>
|
35 |
+
<method>assignBackendModelToAttribute</method>
|
36 |
+
</jvs_fileattribute>
|
37 |
+
</observers>
|
38 |
+
</catalog_entity_attribute_save_before>
|
39 |
+
</events>
|
40 |
+
</global>
|
41 |
+
<adminhtml>
|
42 |
+
<events>
|
43 |
+
<adminhtml_product_attribute_types>
|
44 |
+
<observers>
|
45 |
+
<jvs_fileattribute>
|
46 |
+
<type>model</type>
|
47 |
+
<class>jvs_fileattribute/observer</class>
|
48 |
+
<method>addFileAttributeType</method>
|
49 |
+
</jvs_fileattribute>
|
50 |
+
</observers>
|
51 |
+
</adminhtml_product_attribute_types>
|
52 |
+
<adminhtml_catalog_product_edit_element_types>
|
53 |
+
<observers>
|
54 |
+
<jvs_fileattribute>
|
55 |
+
<class>jvs_fileattribute/observer</class>
|
56 |
+
<method>updateElementTypes</method>
|
57 |
+
</jvs_fileattribute>
|
58 |
+
</observers>
|
59 |
+
</adminhtml_catalog_product_edit_element_types>
|
60 |
+
</events>
|
61 |
+
</adminhtml>
|
62 |
+
<default>
|
63 |
+
<general>
|
64 |
+
<validator_data>
|
65 |
+
<input_types>
|
66 |
+
<jvs_file>jvs_file</jvs_file>
|
67 |
+
</input_types>
|
68 |
+
</validator_data>
|
69 |
+
</general>
|
70 |
+
</default>
|
71 |
+
</config>
|
app/code/community/Jvs/MinTotalQty/Model/Observer.php
CHANGED
@@ -9,14 +9,20 @@
|
|
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
|
18 |
{
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
$customer = Mage::helper('customer')->getCustomer();
|
21 |
|
22 |
// If the minimun total quantity is not met
|
@@ -33,7 +39,7 @@ class Jvs_MinTotalQty_Model_Observer
|
|
33 |
)
|
34 |
);
|
35 |
|
36 |
-
// Check if
|
37 |
if (!Mage::helper('jvs_mintotalqty')->isCartPage()) {
|
38 |
Mage::app()->getFrontController()->getResponse()
|
39 |
->setRedirect(Mage::getUrl('checkout/cart'));
|
9 |
class Jvs_MinTotalQty_Model_Observer
|
10 |
{
|
11 |
/**
|
12 |
+
* Check minimun order totals and redirect if
|
13 |
+
* they do not meet the minimum required
|
14 |
*
|
15 |
* @param Varien_Event_Observer $observer
|
16 |
* @return void
|
17 |
*/
|
18 |
+
public function redirectToCartWhenQuantityNotMet(Varien_Event_Observer $observer)
|
19 |
{
|
20 |
+
// Skip check if cart is empty
|
21 |
+
if (Mage::helper('checkout/cart')->getItemsCount() == 0) {
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
|
25 |
+
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
26 |
$customer = Mage::helper('customer')->getCustomer();
|
27 |
|
28 |
// If the minimun total quantity is not met
|
39 |
)
|
40 |
);
|
41 |
|
42 |
+
// Check if not already on the cart page
|
43 |
if (!Mage::helper('jvs_mintotalqty')->isCartPage()) {
|
44 |
Mage::app()->getFrontController()->getResponse()
|
45 |
->setRedirect(Mage::getUrl('checkout/cart'));
|
app/code/community/Jvs/MinTotalQty/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Jvs_MinTotalQty>
|
5 |
-
<version>
|
6 |
</Jvs_MinTotalQty>
|
7 |
</modules>
|
8 |
<global>
|
@@ -19,14 +19,30 @@
|
|
19 |
</global>
|
20 |
<frontend>
|
21 |
<events>
|
22 |
-
<
|
23 |
<observers>
|
24 |
<jvs_mintotalqty_checkqty>
|
25 |
<class>jvs_mintotalqty/observer</class>
|
26 |
-
<method>
|
27 |
</jvs_mintotalqty_checkqty>
|
28 |
</observers>
|
29 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
</events>
|
31 |
</frontend>
|
32 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Jvs_MinTotalQty>
|
5 |
+
<version>2.0.0</version>
|
6 |
</Jvs_MinTotalQty>
|
7 |
</modules>
|
8 |
<global>
|
19 |
</global>
|
20 |
<frontend>
|
21 |
<events>
|
22 |
+
<controller_action_predispatch_checkout>
|
23 |
<observers>
|
24 |
<jvs_mintotalqty_checkqty>
|
25 |
<class>jvs_mintotalqty/observer</class>
|
26 |
+
<method>redirectToCartWhenQuantityNotMet</method>
|
27 |
</jvs_mintotalqty_checkqty>
|
28 |
</observers>
|
29 |
+
</controller_action_predispatch_checkout>
|
30 |
+
<controller_action_predispatch_checkout_cart_index>
|
31 |
+
<observers>
|
32 |
+
<jvs_mintotalqty_checkqty>
|
33 |
+
<class>jvs_mintotalqty/observer</class>
|
34 |
+
<method>redirectToCartWhenQuantityNotMet</method>
|
35 |
+
</jvs_mintotalqty_checkqty>
|
36 |
+
</observers>
|
37 |
+
</controller_action_predispatch_checkout_cart_index>
|
38 |
+
<controller_action_predispatch_onestepcheckout>
|
39 |
+
<observers>
|
40 |
+
<jvs_mintotalqty_checkqty>
|
41 |
+
<class>jvs_mintotalqty/observer</class>
|
42 |
+
<method>redirectToCartWhenQuantityNotMet</method>
|
43 |
+
</jvs_mintotalqty_checkqty>
|
44 |
+
</observers>
|
45 |
+
</controller_action_predispatch_onestepcheckout>
|
46 |
</events>
|
47 |
</frontend>
|
48 |
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>minorderqty</name>
|
4 |
-
<version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/MIT">MIT</license>
|
7 |
<channel>community</channel>
|
@@ -10,11 +10,11 @@
|
|
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>
|
14 |
<authors><author><name>Javier Villanueva</name><user>javiervd</user><email>javiervd@gmail.com</email></author></authors>
|
15 |
-
<date>2015-
|
16 |
-
<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="
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.3.0</min><max>5.6.14</max></php></required></dependencies>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>minorderqty</name>
|
4 |
+
<version>2.0.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/MIT">MIT</license>
|
7 |
<channel>community</channel>
|
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>Trigger functionality on checkout pages only instead of when quote is saved to improve performance and compatibility issues with ajax add to cart extensions.</notes>
|
14 |
<authors><author><name>Javier Villanueva</name><user>javiervd</user><email>javiervd@gmail.com</email></author></authors>
|
15 |
+
<date>2015-11-11</date>
|
16 |
+
<time>20:21:58</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="Jvs"><dir name="FileAttribute"><dir name="Block"><dir name="Element"><file name="File.php" hash="3cc11497c90e17d239a56474e13d0b08"/></dir><dir name="Product"><dir name="View"><file name="Attributes.php" hash="23804c6ac14597db3147ce47c2b58131"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="fad835c3b52c614614eedd1bdeab633f"/></dir><dir name="Model"><dir name="Attribute"><dir name="Backend"><file name="File.php" hash="b91adc1758e024f248938844103f51da"/></dir></dir><file name="Observer.php" hash="20387ac3ccf11a6b3b7e8b0cfd9b9744"/></dir><dir name="etc"><file name="config.xml" hash="1062d3ff921e91595fb366466e39fad2"/></dir></dir><dir name="MinTotalQty"><dir name="Helper"><file name="Data.php" hash="cb6ecd90ba3d9ce51bd2de32ced57b31"/></dir><dir name="Model"><file name="Observer.php" hash="61db9ef5e403b6758f9467fc791cd2dc"/></dir><dir name="etc"><file name="config.xml" hash="fa57823f6a5c12e48da3b83dccd8aa60"/><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>
|