-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source_M1.php
86 lines (64 loc) · 2.42 KB
/
Source_M1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Mygento\Discount\Generator;
class Source_M1 extends Source
{
public function getCopyright($package = '')
{
$y = date("Y");
return "/**
* @author Mygento
* @package {$package}
* @copyright {$y} NKS LLC. (https://www.mygento.ru)
*/\n\n";
}
public static function getProtectedProperties()
{
$code = [
'name' => '_code',
'value' => null,
'comment' => ''
];
$properties = parent::getProtectedProperties();
return array_merge([$code], $properties);
}
public function getMethod_buildFinalArray()
{
$method = call_user_func(['parent', __FUNCTION__]);
$placeholder = <<<'PHP'
$receiptObj = (object) $receipt;
Mage::dispatchEvent('mygento_discount_recalculation_after', array('modulecode' => $this->_code, 'receipt' => $receiptObj));
return (array)$receiptObj;
PHP;
$method['body'] = sprintf($method['body'], $placeholder);
return $method;
}
public function getMethod_getRecalculated()
{
$method = call_user_func(['parent', __FUNCTION__]);
$placeholder = 'Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo';
$method['comments'] = sprintf($method['comments'], $placeholder);
$placeholder = '$this->generalHelper = Mage::helper($this->_code);';
$method['body'] = sprintf($method['body'], $placeholder);
return $method;
}
public function getMethod_addTaxValue()
{
$method = call_user_func(['parent', __FUNCTION__]);
$placeholder = <<<'PHP'
$storeId = $entity->getStoreId();
$store = $storeId ? Mage::app()->getStore($storeId) : Mage::app()->getStore();
$taxValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue(
$item->getProductId(),
$taxAttributeCode,
$store
);
$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $taxAttributeCode);
if ($attributeModel->getData('frontend_input') == 'select') {
$taxValue = $attributeModel->getSource()->getOptionText($taxValue);
}
return $taxValue;
PHP;
$method['body'] = sprintf($method['body'], $placeholder);
return $method;
}
}