Version Notes
Initial release
Download this release
Release Info
Developer | Javier Villanueva |
Extension | fileuploadattribute |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.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/Helper/Data.php +71 -0
- app/code/community/Jvs/MinTotalQty/Model/Observer.php +45 -0
- app/code/community/Jvs/MinTotalQty/etc/config.xml +32 -0
- app/code/community/Jvs/MinTotalQty/etc/system.xml +22 -0
- app/etc/modules/Jvs_FileAttribute.xml +9 -0
- package.xml +20 -0
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/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_FileAttribute.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Jvs_FileAttribute>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Jvs_FileAttribute>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>fileuploadattribute</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>Create file upload attributes for your products by adding a new input type to the attribute creation form.</summary>
|
10 |
+
<description>This extension allows you to create file upload attributes for your products by adding a new input type to the attribute creation form.
|
11 |
+

|
12 |
+
You will be able to assign multiple file upload attributes to your products, restrict allowed file extensions and choose to display them automatically on your product pages or display it by yourself however you want to.</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-11-10</date>
|
16 |
+
<time>23:02:52</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="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_FileAttribute.xml" hash="23788d82b953b31264288716e8536ba9"/></dir></target></contents>
|
18 |
+
<compatible/>
|
19 |
+
<dependencies><required><php><min>5.3.0</min><max>5.6.14</max></php></required></dependencies>
|
20 |
+
</package>
|