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.7 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.0.6 to 1.0.0.7
app/code/community/VES/PdfProCustomVariables/Model/Observer.php
CHANGED
|
@@ -1,2 +1,217 @@
|
|
| 1 |
<?php
|
| 2 |
-
class VES_PdfProCustomVariables_Model_Observer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
+
class VES_PdfProCustomVariables_Model_Observer
|
| 3 |
+
{
|
| 4 |
+
/**
|
| 5 |
+
* Get All formated date for givent date
|
| 6 |
+
* @param string $date
|
| 7 |
+
* @return Varien_Object
|
| 8 |
+
*/
|
| 9 |
+
public function getFormatedDate($date,$type = null){
|
| 10 |
+
$dateFormated = new Varien_Object(array(
|
| 11 |
+
'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)),
|
| 12 |
+
'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)),
|
| 13 |
+
'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)),
|
| 14 |
+
'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)),
|
| 15 |
+
));
|
| 16 |
+
if($type) return $dateFormated->getData($type);
|
| 17 |
+
return $dateFormated;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
public function isExistAttribute($product, $att_code) {
|
| 22 |
+
$atts = $product->getAttributes();
|
| 23 |
+
foreach($atts as $att) {
|
| 24 |
+
if($att_code == $att->getAttributeCode()) return true;
|
| 25 |
+
}
|
| 26 |
+
return false;
|
| 27 |
+
}
|
| 28 |
+
/**
|
| 29 |
+
* Get all available attribute codes of product
|
| 30 |
+
* @param Mage_Catalog_Model_Product $product
|
| 31 |
+
*/
|
| 32 |
+
public function getAvailableAttributeCodesOfProduct(Mage_Catalog_Model_Product $product){
|
| 33 |
+
$attributes = $product->getAttributes();
|
| 34 |
+
$result = array();
|
| 35 |
+
foreach($attributes as $attribute) {
|
| 36 |
+
$result[$attribute->getAttributeCode()] = $attribute->getAttributeCode();
|
| 37 |
+
}
|
| 38 |
+
return $result;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Get all available attribute codes of customer
|
| 43 |
+
* @param Mage_Catalog_Model_Customer $customer
|
| 44 |
+
*/
|
| 45 |
+
public function getAvailableAttributeCodesOfCustomer(Mage_Customer_Model_Customer $customer){
|
| 46 |
+
$attributes = $customer->getAttributes();
|
| 47 |
+
$result = array();
|
| 48 |
+
foreach($attributes as $attribute) {
|
| 49 |
+
$result[$attribute->getAttributeCode()] = $attribute->getAttributeCode();
|
| 50 |
+
}
|
| 51 |
+
return $result;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function ves_pdfpro_data_prepare_after($observer){
|
| 55 |
+
$type = $observer->getType();
|
| 56 |
+
if($type=='item'){
|
| 57 |
+
$itemData = $observer->getSource();
|
| 58 |
+
$item = $observer->getModel();
|
| 59 |
+
$product = Mage::getModel('catalog/product')->load($item->getProductId());
|
| 60 |
+
$itemProduct = new Varien_Object();
|
| 61 |
+
|
| 62 |
+
if (!($item instanceof Mage_Sales_Model_Order_Item)) {
|
| 63 |
+
$order = $item->getOrderItem()->getOrder();
|
| 64 |
+
}else{
|
| 65 |
+
$order = $item->getOrder();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
$orderCurrencyCode = $order->getOrderCurrencyCode();
|
| 69 |
+
|
| 70 |
+
$availableAttributes = $this->getAvailableAttributeCodesOfProduct($product);
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
$collection = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')->getCollection();
|
| 74 |
+
foreach ($collection->getData() as $data) {
|
| 75 |
+
switch($data['variable_type']) {
|
| 76 |
+
case 'attribute':
|
| 77 |
+
$attributeInfo = new Varien_Object(Mage::getModel('catalog/product_attribute_api')->info($data['attribute_id']));
|
| 78 |
+
switch($attributeInfo->getFrontendInput()) {
|
| 79 |
+
case 'text':
|
| 80 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 81 |
+
$src = $product->getData($attributeInfo->getAttributeCode())
|
| 82 |
+
: $src = '';
|
| 83 |
+
$itemProduct->setData($data['name'], $src);
|
| 84 |
+
break;
|
| 85 |
+
|
| 86 |
+
case 'textarea':
|
| 87 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 88 |
+
$src = $product->getData($attributeInfo->getAttributeCode())
|
| 89 |
+
: $src = '';
|
| 90 |
+
$itemProduct->setData($data['name'], $src);
|
| 91 |
+
break;
|
| 92 |
+
|
| 93 |
+
case 'date':
|
| 94 |
+
if(isset($availableAttributes[$attributeInfo->getAttributeCode()])) {
|
| 95 |
+
$date = $product->getData($attributeInfo->getAttributeCode());
|
| 96 |
+
$dateFormated = new Varien_Object(array(
|
| 97 |
+
'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)),
|
| 98 |
+
'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)),
|
| 99 |
+
'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)),
|
| 100 |
+
'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)),
|
| 101 |
+
));
|
| 102 |
+
$itemProduct->setData($data['name'],$dateFormated);
|
| 103 |
+
}else {
|
| 104 |
+
$itemProduct->setData($data['name'],'');
|
| 105 |
+
}
|
| 106 |
+
break;
|
| 107 |
+
|
| 108 |
+
case 'price':
|
| 109 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 110 |
+
$price = Mage::helper('pdfpro')->currency($product->getData($attributeInfo->getAttributeCode()),$orderCurrencyCode)
|
| 111 |
+
: $price = '';
|
| 112 |
+
$itemProduct->setData($data['name'], $price);
|
| 113 |
+
break;
|
| 114 |
+
|
| 115 |
+
case 'multiselect':
|
| 116 |
+
$label_arr = $product->getAttributeText($attributeInfo->getAttributeCode());
|
| 117 |
+
count($label_arr) == 0 ? $label = '' : $label = implode(',', $label_arr);
|
| 118 |
+
$itemProduct->setData($data['name'], $label);
|
| 119 |
+
break;
|
| 120 |
+
|
| 121 |
+
case 'select':
|
| 122 |
+
(isset($availableAttributes[$attributeInfo->getAttributeCode()]) && $product->getData($attributeInfo->getAttributeCode()) != '') ?
|
| 123 |
+
$label = $product->getResource()->getAttribute($attributeInfo->getAttributeCode())->getFrontend()->getValue($product)
|
| 124 |
+
: $label = '';
|
| 125 |
+
$itemProduct->setData($data['name'], $label);
|
| 126 |
+
break;
|
| 127 |
+
|
| 128 |
+
case 'boolean':
|
| 129 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 130 |
+
$label = $product->getResource()->getAttribute($attributeInfo->getAttributeCode())->getFrontend()->getValue($product)
|
| 131 |
+
: $label = '';
|
| 132 |
+
$itemProduct->setData($data['name'], $label);
|
| 133 |
+
break;
|
| 134 |
+
|
| 135 |
+
case 'media_image':
|
| 136 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 137 |
+
$src = Mage::getBaseUrl('media') . 'catalog/product' . $product->getData($attributeInfo->getAttributeCode())
|
| 138 |
+
: $src = '';
|
| 139 |
+
$itemProduct->setData($data['name'], $src);
|
| 140 |
+
break;
|
| 141 |
+
|
| 142 |
+
default:
|
| 143 |
+
isset($availableAttributes[$attributeInfo->getAttributeCode()]) ?
|
| 144 |
+
$src = $product->getData($attributeInfo->getAttributeCode())
|
| 145 |
+
: $src = '';
|
| 146 |
+
$itemProduct->setData($data['name'], $src);
|
| 147 |
+
break;
|
| 148 |
+
}
|
| 149 |
+
break;
|
| 150 |
+
|
| 151 |
+
case 'static':
|
| 152 |
+
$itemData->setData($data['name'], $data['static_value']);
|
| 153 |
+
break;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
$itemData->setData('product',$itemProduct);
|
| 157 |
+
} else if ($type == 'customer') {
|
| 158 |
+
$customerData = $observer->getSource();
|
| 159 |
+
$item = $observer->getModel();
|
| 160 |
+
$customer = Mage::getModel('customer/customer')->load($item->getId());
|
| 161 |
+
$availableAttributes = $this->getAvailableAttributeCodesOfCustomer($customer);
|
| 162 |
+
$collection = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')->getCollection();
|
| 163 |
+
|
| 164 |
+
foreach($collection->getData() as $data) {
|
| 165 |
+
if($data['variable_type'] == 'customer') {
|
| 166 |
+
$attributeInfo = Mage::getModel('pdfprocustomvariables/pdfprocustomvariables')
|
| 167 |
+
->getAttributeInfo($data['attribute_id_customer']);
|
| 168 |
+
switch($attributeInfo['frontend_input']) {
|
| 169 |
+
case 'text':
|
| 170 |
+
isset($availableAttributes[$attributeInfo['attribute_code']]) ?
|
| 171 |
+
$src = $customer->getData($attributeInfo['attribute_code'])
|
| 172 |
+
: $src = '';
|
| 173 |
+
$customerData->setData($data['name'], $src);
|
| 174 |
+
break;
|
| 175 |
+
|
| 176 |
+
case 'boolean':
|
| 177 |
+
isset($availableAttributes[$attributeInfo['attribute_code']]) ?
|
| 178 |
+
($customer->getData($attributeInfo['attribute_code']) == 1 ? $label = Mage::helper('core/translate')->__('Yes') : $label = Mage::helper('core/translate')->__('No')) : $label = '';
|
| 179 |
+
|
| 180 |
+
$customerData->setData($data['name'], $label);
|
| 181 |
+
break;
|
| 182 |
+
|
| 183 |
+
case 'select':
|
| 184 |
+
(isset($availableAttributes[$attributeInfo['attribute_code']]) && $customer->getData($attributeInfo['attribute_code']) != '') ?
|
| 185 |
+
$label = $customer->getResource()->getAttribute($attributeInfo['attribute_code'])->getFrontend()->getValue($customer)
|
| 186 |
+
: $label = '';
|
| 187 |
+
echo $label;exit;
|
| 188 |
+
$customerData->setData($data['name'], $label);
|
| 189 |
+
break;
|
| 190 |
+
|
| 191 |
+
case 'date':
|
| 192 |
+
if(isset($availableAttributes[$attributeInfo['attribute_code']])) {
|
| 193 |
+
$date = $customer->getData($attributeInfo['attribute_code']);
|
| 194 |
+
$dateFormated = new Varien_Object(array(
|
| 195 |
+
'full' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_FULL)),
|
| 196 |
+
'long' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)),
|
| 197 |
+
'medium' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)),
|
| 198 |
+
'short' => Mage::app()->getLocale()->date(strtotime($date))->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)),
|
| 199 |
+
));
|
| 200 |
+
$customerData->setData($data['name'],$dateFormated);
|
| 201 |
+
}else {
|
| 202 |
+
$customerData->setData($data['name'],'');
|
| 203 |
+
}
|
| 204 |
+
break;
|
| 205 |
+
|
| 206 |
+
default:
|
| 207 |
+
isset($availableAttributes[$attributeInfo['attribute_code']]) ?
|
| 208 |
+
$src = $customer->getData($attributeInfo['attribute_code'])
|
| 209 |
+
: $src = '';
|
| 210 |
+
$customerData->setData($data['name'], $src);
|
| 211 |
+
break;
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
}
|
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.7</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-09-10</date>
|
| 16 |
+
<time>14:25:12</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="1867d5a448ed48821cba5a7a80d9f0ad"/><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>
|
