Version Notes
- Allow to define variable which relate to product attribute
- Allow to define variable which relate to customer attribute
- Allow to define static values
Download this release
Release Info
Developer | Magento Core Team |
Extension | Easy_PDF_Invoice_Custom_Variables |
Version | 1.0.0.6 |
Comparing to | |
See all releases |
Code changes from version 1.0.0.5 to 1.0.0.6
app/code/community/VES/PdfProCustomVariables/Model/Observer.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?php
|
2 |
-
class VES_PdfProCustomVariables_Model_Observer { public function getFormatedDate($date,$type = null){ $dateFormated = new Varien_Object(array( 'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)), 'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)), 'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)), 'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)), )); if($type) return $dateFormated->getData($type); return $dateFormated; } public function isExistAttribute($product, $att_code) { $atts = $product->getAttributes(); foreach($atts as $att) { if($att_code == $att->getAttributeCode()) return true; } return false; } public function getAvailableAttributeCodesOfProduct(Mage_Catalog_Model_Product $product){ $attributes = $product->getAttributes(); $result = array(); foreach($attributes as $attribute) { $result[$attribute->getAttributeCode()] = $attribute->getAttributeCode(); } return $result; } public function getAvailableAttributeCodesOfCustomer(Mage_Catalog_Model_Customer $customer){ $attributes = $customer->getAttributes(); $result = array(); foreach($attributes as $attribute) { $result[$attribute->getAttributeCode()] = $attribute->getAttributeCode(); } return $result; } public function ves_pdfpro_data_prepare_after($observer){ $type = $observer->getType(); if($type=='item'){ $itemData = $observer->getSource(); $item = $observer->getModel(); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $itemProduct = new Varien_Object(); $order = Mage::getModel('sales/order')->load($item->getOrderId()); $orderCurrencyCode = $order->getOrderCurrencyCode(); $availableAttributes = $this->getAvailableAttributeCodesOfProduct($product); $collection = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')->getCollection(); foreach ($collection->getData() as $data) { switch($data['variable_type']) { case 'attribute': $attributeInfo =
|
1 |
<?php
|
2 |
+
class VES_PdfProCustomVariables_Model_Observer { public function getFormatedDate($date,$type = null){ $dateFormated = new Varien_Object(array( 'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)), 'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)), 'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)), 'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)), )); if($type) return $dateFormated->getData($type); return $dateFormated; } public function isExistAttribute($product, $att_code) { $atts = $product->getAttributes(); foreach($atts as $att) { if($att_code == $att->getAttributeCode()) return true; } return false; } public function getAvailableAttributeCodesOfProduct(Mage_Catalog_Model_Product $product){ $attributes = $product->getAttributes(); $result = array(); foreach($attributes as $attribute) { $result[$attribute->getAttributeCode()] = $attribute->getAttributeCode(); } return $result; } public function getAvailableAttributeCodesOfCustomer(Mage_Catalog_Model_Customer $customer){ $attributes = $customer->getAttributes(); $result = array(); foreach($attributes as $attribute) { $result[$attribute->getAttributeCode()] = $attribute->getAttributeCode(); } return $result; } public function ves_pdfpro_data_prepare_after($observer){ $type = $observer->getType(); if($type=='item'){ $itemData = $observer->getSource(); $item = $observer->getModel(); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $itemProduct = new Varien_Object(); $order = Mage::getModel('sales/order')->load($item->getOrderId()); $orderCurrencyCode = $order->getOrderCurrencyCode(); $availableAttributes = $this->getAvailableAttributeCodesOfProduct($product); $collection = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')->getCollection(); foreach ($collection->getData() as $data) { switch($data['variable_type']) { case 'attribute': $attributeInfo = Mage::getModel('catalog/resource_eav_attribute')->setEntityTypeId('product')->load($data['attribute_id']); switch($attributeInfo->getFrontendInput()) { case 'text': isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $src = $product->getData($attributeInfo->getAttributeCode()) : $src = ''; $itemProduct->setData($data['name'], $src); break; case 'textarea': isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $src = $product->getData($attributeInfo->getAttributeCode()) : $src = ''; $itemProduct->setData($data['name'], $src); break; case 'date': if(isset($availableAttributes[$attributeInfo->getAttributeCode()])) { $date = $product->getData($attributeInfo->getAttributeCode()); $dateFormated = new Varien_Object(array( 'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)), 'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)), 'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)), 'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)), )); $itemProduct->setData($data['name'],$dateFormated); }else { $itemProduct->setData($data['name'],''); } break; case 'price': isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $price = Mage::helper('pdfpro')->currency($product->getData($attributeInfo->getAttributeCode()),$orderCurrencyCode) : $price = ''; $itemProduct->setData($data['name'], $price); break; case 'multiselect': $label_arr = $product->getAttributeText($attributeInfo->getAttributeCode()); count($label_arr) == 0 ? $label = '' : $label = implode(',', $label_arr); $itemProduct->setData($data['name'], $label); break; case 'select': (isset($availableAttributes[$attributeInfo->getAttributeCode()]) && $product->getData($attributeInfo->getAttributeCode()) != '') ? $label = $product->getResource()->getAttribute($attributeInfo->getAttributeCode())->getFrontend()->getValue($product) : $label = ''; $itemProduct->setData($data['name'], $label); break; case 'boolean': isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $label = $product->getResource()->getAttribute($attributeInfo->getAttributeCode())->getFrontend()->getValue($product) : $label = ''; $itemProduct->setData($data['name'], $label); break; case 'media_image': isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $src = Mage::getBaseUrl('media') . 'catalog/product' . $product->getData($attributeInfo->getAttributeCode()) : $src = ''; $itemProduct->setData($data['name'], $src); break; default: isset($availableAttributes[$attributeInfo->getAttributeCode()]) ? $src = $product->getData($attributeInfo->getAttributeCode()) : $src = ''; $itemProduct->setData($data['name'], $src); break; } break; case 'static': $itemData->setData($data['name'], $data['static_value']); break; } } $itemData->setData('product',$itemProduct); } else if ($type == 'customer') { $customerData = $observer->getSource(); $item = $observer->getModel(); $customer = Mage::getModel('customer/customer')->load($item->getId()); $availableAttributes = $this->getAvailableAttributeCodesOfCustomer($customer); $collection = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')->getCollection(); foreach($collection->getData() as $data) { if($data['variable_type'] == 'customer') { $attributeInfo = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables') ->getAttributeInfo($data['attribute_id_customer']); switch($attributeInfo['frontend_input']) { case 'text': isset($availableAttributes[$attributeInfo['attribute_code']]) ? $src = $customer->getData($attributeInfo['attribute_code']) : $src = ''; $customerData->setData($data['name'], $src); break; case 'boolean': isset($availableAttributes[$attributeInfo['attribute_code']]) ? ($customer->getData($attributeInfo['attribute_code']) == 1 ? $label = Mage::helper('core/translate')->__('Yes') : $label = Mage::helper('core/translate')->__('No')) : $label = ''; $customerData->setData($data['name'], $label); break; case 'select': (isset($availableAttributes[$attributeInfo['attribute_code']]) && $customer->getData($attributeInfo['attribute_code']) != '') ? $label = $customer->getResource()->getAttribute($attributeInfo['attribute_code'])->getFrontend()->getValue($customer) : $label = ''; echo $label;exit; $customerData->setData($data['name'], $label); break; case 'date': if(isset($availableAttributes[$attributeInfo['attribute_code']])) { $date = $customer->getData($attributeInfo['attribute_code']); $dateFormated = new Varien_Object(array( 'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)), 'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)), 'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)), 'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)), )); $customerData->setData($data['name'],$dateFormated); }else { $customerData->setData($data['name'],''); } break; default: isset($availableAttributes[$attributeInfo['attribute_code']]) ? $src = $customer->getData($attributeInfo['attribute_code']) : $src = ''; $customerData->setData($data['name'], $src); break; } } } } } }
|
app/code/community/VES/PdfProCustomVariables/Model/Pdfprocustomvariables.php
CHANGED
@@ -12,7 +12,7 @@ class VES_PdfProCustomVariables_Model_Pdfprocustomvariables extends Mage_Core_Mo
|
|
12 |
switch($variable->getData('variable_type')){
|
13 |
case 'attribute':
|
14 |
$attributeId = $variable->getAttributeId();
|
15 |
-
$attributeInfo
|
16 |
break;
|
17 |
case 'customer':
|
18 |
$attributeId = $variable->getAttributeIdCustomer();
|
12 |
switch($variable->getData('variable_type')){
|
13 |
case 'attribute':
|
14 |
$attributeId = $variable->getAttributeId();
|
15 |
+
$attributeInfo = Mage::getModel('catalog/resource_eav_attribute')->setEntityTypeId('product')->load($attributeId)->getData();
|
16 |
break;
|
17 |
case 'customer':
|
18 |
$attributeId = $variable->getAttributeIdCustomer();
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Easy_PDF_Invoice_Custom_Variables</name>
|
4 |
-
<version>1.0.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL V3.0</license>
|
7 |
<channel>community</channel>
|
@@ -12,9 +12,9 @@
|
|
12 |
- Allow to define variable which relate to customer attribute
|
13 |
- Allow to define static values</notes>
|
14 |
<authors><author><name>Easy PDF Invoice</name><user>auto-converted</user><email>easypdfinvoice@gmail.com</email></author></authors>
|
15 |
-
<date>2013-
|
16 |
-
<time>
|
17 |
-
<contents><target name="mageetc"><dir name="modules"><file name="VES_PdfProCustomVariables.xml" hash="f13346f67bbae21fdb87a393a4663ea5"/></dir></target><target name="magecommunity"><dir name="VES"><dir name="PdfProCustomVariables"><dir name="Block"><dir name="Adminhtml"><dir name="Pdfprocustomvariables"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="3870bf494d27ac725fdf0277bcaff17e"/><file name="Intergration.php" hash="236d9e8f74e88befcc05a3d848a8ae56"/></dir><file name="Form.php" hash="1f87d9ee6ce3df463f027ff96aae6cda"/><file name="Tabs.php" hash="1261d8486ffd5c6f41af7e97ddbd56e8"/></dir><file name="Edit.php" hash="25810b8c5ca254c10a0e981e1639e7b9"/><file name="Grid.php" hash="2f8f5025bb9df25d4c2a473821fd74fe"/></dir><file name="Pdfprocustomvariables.php" hash="91f8d4310da8f8da46c6a142e5b38738"/></dir></dir><dir name="Helper"><file name="Data.php" hash="2aba96822fcc8fb043792d40baa2e90a"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Pdfprocustomvariables"><file name="Collection.php" hash="96ce5d49fee8ca2e52164714a42a9b28"/></dir><file name="Pdfprocustomvariables.php" hash="4718330435a78a6313914cb5e062d3d7"/></dir><file name="Observer.php" hash="
|
18 |
<compatible/>
|
19 |
<dependencies/>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Easy_PDF_Invoice_Custom_Variables</name>
|
4 |
+
<version>1.0.0.6</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL V3.0</license>
|
7 |
<channel>community</channel>
|
12 |
- Allow to define variable which relate to customer attribute
|
13 |
- Allow to define static values</notes>
|
14 |
<authors><author><name>Easy PDF Invoice</name><user>auto-converted</user><email>easypdfinvoice@gmail.com</email></author></authors>
|
15 |
+
<date>2013-04-11</date>
|
16 |
+
<time>16:22:51</time>
|
17 |
+
<contents><target name="mageetc"><dir name="modules"><file name="VES_PdfProCustomVariables.xml" hash="f13346f67bbae21fdb87a393a4663ea5"/></dir></target><target name="magecommunity"><dir name="VES"><dir name="PdfProCustomVariables"><dir name="Block"><dir name="Adminhtml"><dir name="Pdfprocustomvariables"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="3870bf494d27ac725fdf0277bcaff17e"/><file name="Intergration.php" hash="236d9e8f74e88befcc05a3d848a8ae56"/></dir><file name="Form.php" hash="1f87d9ee6ce3df463f027ff96aae6cda"/><file name="Tabs.php" hash="1261d8486ffd5c6f41af7e97ddbd56e8"/></dir><file name="Edit.php" hash="25810b8c5ca254c10a0e981e1639e7b9"/><file name="Grid.php" hash="2f8f5025bb9df25d4c2a473821fd74fe"/></dir><file name="Pdfprocustomvariables.php" hash="91f8d4310da8f8da46c6a142e5b38738"/></dir></dir><dir name="Helper"><file name="Data.php" hash="2aba96822fcc8fb043792d40baa2e90a"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Pdfprocustomvariables"><file name="Collection.php" hash="96ce5d49fee8ca2e52164714a42a9b28"/></dir><file name="Pdfprocustomvariables.php" hash="4718330435a78a6313914cb5e062d3d7"/></dir><file name="Observer.php" hash="885e07ac54cd5448ab16082c96683b50"/><file name="Pdfprocustomvariables.php" hash="57161bc69c6c478d4f084b4cd4e5e766"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="VariablesController.php" hash="13b5cccde7acdc30197eb258975916ff"/></dir></dir><dir name="etc"><file name="config.xml" hash="fab63b17cf036596080c7a4b88da99c6"/></dir><dir name="sql"><dir name="pdfprocustomvariables_setup"><file name="mysql4-install-1.0.0.php" hash="203b4b818ccba7bd2107ae1047192b42"/><file name="mysql4-upgrade-1.0.0-1.0.0.1.php" hash="05564671ba8ea3cad6c07202921f1b5a"/><file name="mysql4-upgrade-1.0.0.1-1.0.0.2.php" hash="a036e5b1226ff5bfcdf8181ac983b5e0"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="ves_pdfprocustomvariables.xml" hash="347f0604dabbc274177ab47b06587cf3"/></dir><dir name="template"><dir name="ves_pdfprocustomvariables"><file name="intergrationcode.phtml" hash="abdd9e53f9f63fe0b945b4af075f3d7b"/></dir></dir></dir></dir></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies/>
|
20 |
</package>
|