Version Notes
Use attribute output helper instead of rewrite
Download this release
Release Info
Developer | Javier Villanueva |
Extension | fileuploadattribute |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.0 to 1.3.0
- app/code/community/Jvs/FileAttribute/.DS_Store +0 -0
- app/code/community/Jvs/FileAttribute/Block/.DS_Store +0 -0
- app/code/community/Jvs/FileAttribute/Block/Product/View/Attributes.php +0 -56
- app/code/community/Jvs/FileAttribute/Helper/.DS_Store +0 -0
- app/code/community/Jvs/FileAttribute/Helper/Data.php +20 -0
- app/code/community/Jvs/FileAttribute/Model/.DS_Store +0 -0
- app/code/community/Jvs/FileAttribute/Model/Observer.php +13 -0
- app/code/community/Jvs/FileAttribute/etc/.DS_Store +0 -0
- app/code/community/Jvs/FileAttribute/etc/config.xml +13 -5
- package.xml +5 -5
app/code/community/Jvs/FileAttribute/.DS_Store
ADDED
Binary file
|
app/code/community/Jvs/FileAttribute/Block/.DS_Store
ADDED
Binary file
|
app/code/community/Jvs/FileAttribute/Block/Product/View/Attributes.php
DELETED
@@ -1,56 +0,0 @@
|
|
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/.DS_Store
ADDED
Binary file
|
app/code/community/Jvs/FileAttribute/Helper/Data.php
CHANGED
@@ -8,5 +8,25 @@
|
|
8 |
*/
|
9 |
class Jvs_FileAttribute_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
8 |
*/
|
9 |
class Jvs_FileAttribute_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
{
|
11 |
+
/**
|
12 |
+
* Change file input display output to a download link
|
13 |
+
*
|
14 |
+
* @param Mage_Catalog_Helper_Output $outputHelper
|
15 |
+
* @param string $outputHtml
|
16 |
+
* @param array $params
|
17 |
+
* @return string
|
18 |
+
*/
|
19 |
+
public function productAttribute(Mage_Catalog_Helper_Output $outputHelper, $outputHtml, $params)
|
20 |
+
{
|
21 |
+
/** @var $product Mage_Catalog_Model_Product */
|
22 |
+
$product = $params['product'];
|
23 |
|
24 |
+
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $params['attribute']);
|
25 |
+
|
26 |
+
if ($attribute && ($attribute->getFrontendInput() == 'jvs_file') && ($attributeValue = $product->getData($params['attribute']))) {
|
27 |
+
$outputHtml = sprintf('<a href="%s" download>%s</a>', $this->escapeUrl(Mage::getBaseUrl('media') . 'catalog/product' . $attributeValue), Mage::helper('jvs_fileattribute')->__('Download'));
|
28 |
+
}
|
29 |
+
|
30 |
+
return $outputHtml;
|
31 |
+
}
|
32 |
}
|
app/code/community/Jvs/FileAttribute/Model/.DS_Store
ADDED
Binary file
|
app/code/community/Jvs/FileAttribute/Model/Observer.php
CHANGED
@@ -102,4 +102,17 @@ class Jvs_FileAttribute_Model_Observer
|
|
102 |
|
103 |
return $this;
|
104 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
}
|
102 |
|
103 |
return $this;
|
104 |
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Change file attribute display output
|
108 |
+
*
|
109 |
+
* @param Varien_Event_Observer $observer
|
110 |
+
* @return void
|
111 |
+
*/
|
112 |
+
public function changeFileAttributeOutput(Varien_Event_Observer $observer)
|
113 |
+
{
|
114 |
+
$outputHelper = $observer->getHelper();
|
115 |
+
$helper = Mage::helper('jvs_fileattribute');
|
116 |
+
$outputHelper->addHandler('productAttribute', $helper);
|
117 |
+
}
|
118 |
}
|
app/code/community/Jvs/FileAttribute/etc/.DS_Store
ADDED
Binary file
|
app/code/community/Jvs/FileAttribute/etc/config.xml
CHANGED
@@ -10,11 +10,6 @@
|
|
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>
|
@@ -67,6 +62,19 @@
|
|
67 |
</adminhtml_catalog_product_form_prepare_excluded_field_list>
|
68 |
</events>
|
69 |
</adminhtml>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
<default>
|
71 |
<general>
|
72 |
<validator_data>
|
10 |
<jvs_fileattribute>
|
11 |
<class>Jvs_FileAttribute_Block</class>
|
12 |
</jvs_fileattribute>
|
|
|
|
|
|
|
|
|
|
|
13 |
</blocks>
|
14 |
<models>
|
15 |
<jvs_fileattribute>
|
62 |
</adminhtml_catalog_product_form_prepare_excluded_field_list>
|
63 |
</events>
|
64 |
</adminhtml>
|
65 |
+
<frontend>
|
66 |
+
<events>
|
67 |
+
<catalog_helper_output_construct>
|
68 |
+
<observers>
|
69 |
+
<jvs_fileattribute>
|
70 |
+
<type>singleton</type>
|
71 |
+
<class>jvs_fileattribute/observer</class>
|
72 |
+
<method>changeFileAttributeOutput</method>
|
73 |
+
</jvs_fileattribute>
|
74 |
+
</observers>
|
75 |
+
</catalog_helper_output_construct>
|
76 |
+
</events>
|
77 |
+
</frontend>
|
78 |
<default>
|
79 |
<general>
|
80 |
<validator_data>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>fileuploadattribute</name>
|
4 |
-
<version>1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/MIT">MIT</license>
|
7 |
<channel>community</channel>
|
@@ -10,11 +10,11 @@
|
|
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>
|
14 |
<authors><author><name>Javier Villanueva</name><user>javiervd</user><email>javiervd@gmail.com</email></author></authors>
|
15 |
-
<date>2016-
|
16 |
-
<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><
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.3.0</min><max>7.0.4</max></php></required></dependencies>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>fileuploadattribute</name>
|
4 |
+
<version>1.3.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/MIT">MIT</license>
|
7 |
<channel>community</channel>
|
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>Use attribute output helper instead of rewrite</notes>
|
14 |
<authors><author><name>Javier Villanueva</name><user>javiervd</user><email>javiervd@gmail.com</email></author></authors>
|
15 |
+
<date>2016-04-02</date>
|
16 |
+
<time>20:12:18</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><file name=".DS_Store" hash="ebce7d54cccacf1bd448203eb4bbd561"/></dir><dir name="Helper"><file name="Data.php" hash="a47a857c8cca8551d88da798e52785d5"/><file name=".DS_Store" hash="437544c43163b0c119f0d54b3165090c"/></dir><dir name="Model"><dir name="Attribute"><dir name="Backend"><file name="File.php" hash="eadb7ec113ccb821ad696a5275f72f5f"/></dir></dir><file name="Observer.php" hash="2e5bf7a02e92ac5760ac6820e1c810a0"/><file name=".DS_Store" hash="e6214ab42c38117d470985232dd26489"/></dir><dir name="etc"><file name="config.xml" hash="bbca70ea5022886a43bcf4fc46b7d9ea"/><file name=".DS_Store" hash="c8a94f9995370bbee66fb1e6790a2bcc"/></dir><file name=".DS_Store" hash="d22cbfb00c2760c947b1a31b45181077"/></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>7.0.4</max></php></required></dependencies>
|
20 |
</package>
|