Public Member Functions | |
setWeeeRendererInForm (Varien_Event_Observer $observer) | |
updateExcludedFieldList (Varien_Event_Observer $observer) | |
prepareCatalogIndexSelect (Varien_Event_Observer $observer) | |
addWeeeTaxAttributeType (Varien_Event_Observer $observer) | |
assignBackendModelToAttribute (Varien_Event_Observer $observer) | |
updateElementTypes (Varien_Event_Observer $observer) | |
updateDiscountPercents (Varien_Event_Observer $observer) | |
updateCofigurableProductOptions (Varien_Event_Observer $observer) | |
updateBundleProductOptions (Varien_Event_Observer $observer) | |
Protected Member Functions | |
_getSelect () |
Definition at line 27 of file Observer.php.
_getSelect | ( | ) | [protected] |
Definition at line 136 of file Observer.php.
00137 { 00138 return Mage::getSingleton('weee/tax')->getResource()->getReadConnection()->select(); 00139 }
addWeeeTaxAttributeType | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 141 of file Observer.php.
00142 { 00143 // adminhtml_product_attribute_types 00144 00145 $response = $observer->getEvent()->getResponse(); 00146 $types = $response->getTypes(); 00147 $types[] = array( 00148 'value' => 'weee', 00149 'label' => Mage::helper('weee')->__('Fixed Product Tax'), 00150 'hide_fields' => array( 00151 'is_unique', 00152 'is_required', 00153 'frontend_class', 00154 'is_configurable', 00155 00156 '_scope', 00157 '_default_value', 00158 '_front_fieldset', 00159 ), 00160 'disabled_types' => array( 00161 'grouped', 00162 ) 00163 ); 00164 00165 $response->setTypes($types); 00166 }
assignBackendModelToAttribute | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 168 of file Observer.php.
00169 { 00170 $backendModel = 'weee/attribute_backend_weee_tax'; 00171 $object = $observer->getEvent()->getAttribute(); 00172 if ($object->getFrontendInput() == 'weee') { 00173 $object->setBackendModel($backendModel); 00174 if (!$object->getApplyTo()) { 00175 $applyTo = array(); 00176 foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { 00177 if ($option['value'] == 'grouped') { 00178 continue; 00179 } 00180 $applyTo[] = $option['value']; 00181 } 00182 $object->setApplyTo($applyTo); 00183 } 00184 } 00185 }
prepareCatalogIndexSelect | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 59 of file Observer.php.
00060 { 00061 if (!Mage::helper('weee')->isEnabled($observer->getEvent()->getStoreId())) { 00062 return $this; 00063 } 00064 00065 switch(Mage::helper('weee')->getListPriceDisplayType()) { 00066 case 2: 00067 case 3: 00068 return $this; 00069 } 00070 00071 $select = $observer->getEvent()->getSelect(); 00072 $table = $observer->getEvent()->getTable(); 00073 $storeId = $observer->getEvent()->getStoreId(); 00074 00075 $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); 00076 $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); 00077 00078 $response = $observer->getEvent()->getResponseObject(); 00079 00080 $additionalCalculations = $response->getAdditionalCalculations(); 00081 00082 $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(); 00083 if ($attributes && Mage::helper('weee')->isDiscounted()) { 00084 $discountField = 'IFNULL(_discount_percent.value, 0)'; 00085 $joinConditions = array( 00086 "_discount_percent.entity_id = {$table}.entity_id", 00087 "_discount_percent.website_id = '{$websiteId}'", 00088 "_discount_percent.customer_group_id = '{$customerGroupId}'", 00089 ); 00090 $select->joinLeft(array('_discount_percent'=>Mage::getSingleton('weee/tax')->getResource()->getTable('weee/discount')), implode(' AND ', $joinConditions), array()); 00091 } 00092 foreach ($attributes as $attribute) { 00093 $tableAlias = "weee_{$attribute}_table"; 00094 00095 if (Mage::helper('weee')->isDiscounted()) { 00096 $additionalCalculations[] = "+(IFNULL({$tableAlias}.value, 0)*(1-({$discountField}/100)))"; 00097 } else { 00098 $additionalCalculations[] = "+(IFNULL({$tableAlias}.value, 0))"; 00099 } 00100 } 00101 $response->setAdditionalCalculations($additionalCalculations); 00102 00103 $rateRequest = Mage::getSingleton('tax/calculation')->getRateRequest(); 00104 $attributes = array(); 00105 $attributes = Mage::getSingleton('weee/tax')->getWeeeTaxAttributeCodes(); 00106 foreach ($attributes as $attribute) { 00107 $attributeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', $attribute); 00108 00109 $tableAlias = "weee_{$attribute}_table"; 00110 $on = array(); 00111 $on[] = "{$tableAlias}.attribute_id = '{$attributeId}'"; 00112 $on[] = "({$tableAlias}.website_id in ('{$websiteId}', 0))"; 00113 00114 $country = $rateRequest->getCountryId(); 00115 $on[] = "({$tableAlias}.country = '{$country}')"; 00116 00117 $region = $rateRequest->getRegionId(); 00118 $on[] = "({$tableAlias}.state in ('{$region}', '*'))"; 00119 00120 $attributeSelect = $this->_getSelect(); 00121 $attributeSelect->from(array($tableAlias=>Mage::getSingleton('weee/tax')->getResource()->getTable('weee/tax'))); 00122 00123 00124 foreach ($on as $one) { 00125 $attributeSelect->where($one); 00126 } 00127 $attributeSelect->limit(1); 00128 00129 $order = array($tableAlias.'.state DESC', $tableAlias.'.website_id DESC'); 00130 00131 $attributeSelect->order($order); 00132 $select->joinLeft(array($tableAlias=>$attributeSelect), $table.'.entity_id = '.$tableAlias.'.entity_id', array()); 00133 } 00134 }
setWeeeRendererInForm | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 29 of file Observer.php.
00030 { 00031 //adminhtml_catalog_product_edit_prepare_form 00032 00033 $form = $observer->getEvent()->getForm(); 00034 $product = $observer->getEvent()->getProduct(); 00035 00036 $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true); 00037 foreach ($attributes as $code) { 00038 if ($weeeTax = $form->getElement($code)) { 00039 $weeeTax->setRenderer( 00040 Mage::app()->getLayout()->createBlock('weee/renderer_weee_tax') 00041 ); 00042 } 00043 } 00044 }
updateBundleProductOptions | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 229 of file Observer.php.
00230 { 00231 if (!Mage::helper('weee')->isEnabled()) { 00232 return $this; 00233 } 00234 00235 $response = $observer->getEvent()->getResponseObject(); 00236 $selection = $observer->getEvent()->getSelection(); 00237 $options = $response->getAdditionalOptions(); 00238 00239 $_product = Mage::registry('current_product'); 00240 if (!Mage::helper('weee')->typeOfDisplay($_product, array(0, 1, 4))) { 00241 return $this; 00242 } 00243 $typeDynamic = Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes_Extend::DYNAMIC; 00244 if (!$_product || $_product->getPriceType() != $typeDynamic) { 00245 return $this; 00246 } 00247 00248 $amount = Mage::helper('weee')->getAmount($selection); 00249 $options['plusDisposition'] = $amount; 00250 00251 $response->setAdditionalOptions($options); 00252 00253 return $this; 00254 }
updateCofigurableProductOptions | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 202 of file Observer.php.
00203 { 00204 if (!Mage::helper('weee')->isEnabled()) { 00205 return $this; 00206 } 00207 00208 $response = $observer->getEvent()->getResponseObject(); 00209 $options = $response->getAdditionalOptions(); 00210 00211 $_product = Mage::registry('current_product'); 00212 if (!$_product) { 00213 return $this; 00214 } 00215 if (!Mage::helper('weee')->typeOfDisplay($_product, array(0, 1, 4))) { 00216 return $this; 00217 } 00218 $amount = Mage::helper('weee')->getAmount($_product); 00219 $origAmount = Mage::helper('weee')->getOriginalAmount($_product); 00220 00221 $options['oldPlusDisposition'] = $origAmount; 00222 $options['plusDisposition'] = $amount; 00223 00224 $response->setAdditionalOptions($options); 00225 00226 return $this; 00227 }
updateDiscountPercents | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 196 of file Observer.php.
00197 { 00198 Mage::getModel('weee/tax')->updateDiscountPercents(); 00199 return $this; 00200 }
updateElementTypes | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 187 of file Observer.php.
00188 { 00189 $response = $observer->getEvent()->getResponse(); 00190 $types = $response->getTypes(); 00191 $types['weee'] = Mage::getConfig()->getBlockClassName('weee/element_weee_tax'); 00192 $response->setTypes($types); 00193 return $this; 00194 }
updateExcludedFieldList | ( | Varien_Event_Observer $ | observer | ) |
Definition at line 46 of file Observer.php.
00047 { 00048 //adminhtml_catalog_product_form_prepare_excluded_field_list 00049 00050 $block = $observer->getEvent()->getObject(); 00051 $list = $block->getFormExcludedFieldList(); 00052 $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true); 00053 foreach ($attributes as $code) { 00054 $list[] = $code; 00055 } 00056 $block->setFormExcludedFieldList($list); 00057 }