Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Weee - DOC block update #744

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget
implements Varien_Data_Form_Element_Renderer_Interface
class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface
{
/**
* Object being rendered
Expand Down Expand Up @@ -225,13 +224,15 @@ public function getWebsites()
*/
protected function _setAddButton()
{
$this->setChild('add_button',
$this->setChild(
'add_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array('id' => "add_tax_" . $this->getElement()->getHtmlId(),
'label' => Mage::helper('catalog')->__('Add Tax'),
'onclick' => "weeeTaxControl.addItem('" . $this->getElement()->getHtmlId() . "')",
'class' => 'add'
)));
))
);
}

/**
Expand All @@ -244,4 +245,3 @@ public function getAddButtonHtml()
return $this->getChildHtml('add_button');
}
}

49 changes: 34 additions & 15 deletions app/code/core/Mage/Weee/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,13 @@ public function typeOfDisplay($product, $compareTo = null, $zone = null, $store
* @param bool $calculateTaxes
* @return array
*/
public function getProductWeeeAttributes($product, $shipping = null, $billing = null,
$website = null, $calculateTaxes = false)
{
public function getProductWeeeAttributes(
$product,
$shipping = null,
$billing = null,
$website = null,
$calculateTaxes = false
) {
return Mage::getSingleton('weee/tax')
->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTaxes);
}
Expand Down Expand Up @@ -313,9 +317,13 @@ public function getProductWeeeAttributesForDisplay($product)
* @param mixed $calculateTaxes
* @return array
*/
public function getProductWeeeAttributesForRenderer($product, $shipping = null, $billing = null,
$website = null, $calculateTaxes = false)
{
public function getProductWeeeAttributesForRenderer(
$product,
$shipping = null,
$billing = null,
$website = null,
$calculateTaxes = false
) {
if ($this->isEnabled()) {
return $this->getProductWeeeAttributes(
$product,
Expand All @@ -337,13 +345,18 @@ public function getProductWeeeAttributesForRenderer($product, $shipping = null,
public function getAmountForDisplay($product)
{
if ($this->isEnabled()) {
$attributes = $this->getProductWeeeAttributesForRenderer($product,
null, null, null, true);
$attributes = $this->getProductWeeeAttributesForRenderer(
$product,
null,
null,
null,
true
);

if (is_array($attributes)) {
$amount = 0;
foreach ($attributes as $attribute) {
/* @var $attribute Varien_Object */
/* @var Varien_Object $attribute */
$amount += $attribute->getAmount();
}
return $amount;
Expand All @@ -361,8 +374,13 @@ public function getAmountForDisplay($product)
public function getAmountForDisplayInclTaxes($product)
{
if ($this->isEnabled()) {
$attributes = $this->getProductWeeeAttributesForRenderer($product,
null, null, null, true);
$attributes = $this->getProductWeeeAttributesForRenderer(
$product,
null,
null,
null,
true
);
return $this->getAmountInclTaxes($attributes);
}
return 0;
Expand Down Expand Up @@ -398,10 +416,12 @@ public function processTierPrices($product, &$tierPrices, $includeIndex = true)
foreach ($tierPrices as $index => &$tier) {
$spanTag = '<span class="price tier-' . ($includeIndex ? $index : 'fixed');
$html = $store->formatPrice($store->convertPrice(
Mage::helper('tax')->getPrice($product, $tier['website_price'], true) + $weeeAmountInclTax), false);
Mage::helper('tax')->getPrice($product, $tier['website_price'], true) + $weeeAmountInclTax
), false);
$tier['formated_price_incl_weee'] = $spanTag . '-incl-tax">' . $html . '</span>';
$html = $store->formatPrice($store->convertPrice(
Mage::helper('tax')->getPrice($product, $tier['website_price']) + $weeeAmount), false);
Mage::helper('tax')->getPrice($product, $tier['website_price']) + $weeeAmount
), false);
$tier['formated_price_incl_weee_only'] = $spanTag . '">' . $html . '</span>';
$tier['formated_weee'] = $store->formatPrice($store->convertPrice($weeeAmount));
}
Expand Down Expand Up @@ -445,7 +465,7 @@ public function getAmountInclTaxes($attributes)
if (is_array($attributes)) {
$amount = 0;
foreach ($attributes as $attribute) {
/* @var $attribute Varien_Object */
/* @var Varien_Object $attribute */
$amount += $attribute->getAmount() + $attribute->getTaxAmount();
}
} else {
Expand Down Expand Up @@ -685,4 +705,3 @@ protected function _getHelper($helperName)
return Mage::helper($helperName);
}
}

18 changes: 15 additions & 3 deletions app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

class Mage_Weee_Model_Attribute_Backend_Weee_Tax extends Mage_Catalog_Model_Product_Attribute_Backend_Price
{
/**
* @return string
*/
public static function getBackendModelName()
{
return 'weee/attribute_backend_weee_tax';
Expand Down Expand Up @@ -82,7 +85,7 @@ public function afterLoad($object)
{
$data = $this->_getResource()->loadProductData($object, $this->getAttribute());

foreach ($data as $i=>$row) {
foreach ($data as $i => $row) {
if ($data[$i]['website_id'] == 0) {
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate(Mage::app()->getBaseCurrencyCode());
if ($rate) {
Expand All @@ -93,12 +96,15 @@ public function afterLoad($object)
} else {
$data[$i]['website_value'] = $data[$i]['value'];
}

}
$object->setData($this->getAttribute()->getName(), $data);
return $this;
}

/**
* @param Mage_Catalog_Model_Product $object
* @return $this|Mage_Catalog_Model_Product_Attribute_Backend_Price
*/
public function afterSave($object)
{
$orig = $object->getOrigData($this->getAttribute()->getName());
Expand Down Expand Up @@ -138,15 +144,21 @@ public function afterSave($object)
return $this;
}

/**
* @param Varien_Object $object
* @return $this|Mage_Eav_Model_Entity_Attribute_Backend_Abstract
*/
public function afterDelete($object)
{
$this->_getResource()->deleteProductData($object, $this->getAttribute());
return $this;
}

/**
* @return string
*/
public function getTable()
{
return $this->_getResource()->getTable('weee/tax');
}
}

4 changes: 3 additions & 1 deletion app/code/core/Mage/Weee/Model/Config/Source/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
class Mage_Weee_Model_Config_Source_Display
{

/**
* @return array
*/
public function toOptionArray()
{
/**
Expand All @@ -51,5 +54,4 @@ public function toOptionArray()
),
);
}

}
2 changes: 0 additions & 2 deletions app/code/core/Mage/Weee/Model/Config/Source/Fpt/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,3 @@ protected function _getHelper($helperName)
return Mage::helper($helperName);
}
}


27 changes: 16 additions & 11 deletions app/code/core/Mage/Weee/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class Mage_Weee_Model_Observer extends Mage_Core_Model_Abstract
public function setWeeeRendererInForm(Varien_Event_Observer $observer)
{
//adminhtml_catalog_product_edit_prepare_form

/** @var Varien_Data_Form $form */
$form = $observer->getEvent()->getForm();
// $product = $observer->getEvent()->getProduct();

$attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true);
foreach ($attributes as $code) {
Expand All @@ -69,6 +68,7 @@ public function updateExcludedFieldList(Varien_Event_Observer $observer)
{
//adminhtml_catalog_product_form_prepare_excluded_field_list

/** @var Mage_Adminhtml_Block_Catalog_Product_Edit_Action_Attribute_Tab_Attributes $block */
$block = $observer->getEvent()->getObject();
$list = $block->getFormExcludedFieldList();
$attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true);
Expand Down Expand Up @@ -98,13 +98,14 @@ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer)
return $this;
}

/** @var $select Varien_Db_Select */
/** @var Varien_Db_Select $select */
$select = $observer->getEvent()->getSelect();
$table = $observer->getEvent()->getTable();

$websiteId = (int)Mage::app()->getStore($storeId)->getWebsiteId();
$customerGroupId = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();

/** @var Varien_Object $response */
$response = $observer->getEvent()->getResponseObject();
$additionalCalculations = $response->getAdditionalCalculations();

Expand All @@ -124,7 +125,10 @@ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer)
);
}
$checkDiscountField = $select->getAdapter()->getCheckSql(
'discount_percent.value IS NULL', 0, 'discount_percent.value');
'discount_percent.value IS NULL',
0,
'discount_percent.value'
);
foreach ($attributes as $attribute) {
$fieldAlias = sprintf('weee_%s_table.value', $attribute);
$checkAdditionalCalculation = $select->getAdapter()->getCheckSql("{$fieldAlias} IS NULL", 0, $fieldAlias);
Expand All @@ -136,7 +140,7 @@ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer)
}
$response->setAdditionalCalculations($additionalCalculations);

/** @var $rateRequest Varien_Object */
/** @var Varien_Object $rateRequest */
$rateRequest = Mage::getSingleton('tax/calculation')->getRateRequest();

$attributes = Mage::getSingleton('weee/tax')->getWeeeTaxAttributeCodes();
Expand Down Expand Up @@ -223,7 +227,7 @@ public function addWeeeTaxAttributeType(Varien_Event_Observer $observer)
public function assignBackendModelToAttribute(Varien_Event_Observer $observer)
{
$backendModel = Mage_Weee_Model_Attribute_Backend_Weee_Tax::getBackendModelName();
/** @var $object Mage_Eav_Model_Entity_Attribute_Abstract */
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $object */
$object = $observer->getEvent()->getAttribute();
if ($object->getFrontendInput() == 'weee') {
$object->setBackendModel($backendModel);
Expand All @@ -245,7 +249,8 @@ public function assignBackendModelToAttribute(Varien_Event_Observer $observer)
/**
* Add custom element type for attributes form
*
* @param Varien_Event_Observer $observer
* @param Varien_Event_Observer $observer
* @return Mage_Weee_Model_Observer
*/
public function updateElementTypes(Varien_Event_Observer $observer)
{
Expand Down Expand Up @@ -287,7 +292,7 @@ public function updateDiscountPercents(Varien_Event_Observer $observer)
*/
public function updateCofigurableProductOptions(Varien_Event_Observer $observer)
{
/* @var $weeeHelper Mage_Weee_Helper_Data */
/* @var Mage_Weee_Helper_Data $weeeHelper */
$weeeHelper = Mage::helper('weee');
if (!$weeeHelper->isEnabled()) {
return $this;
Expand Down Expand Up @@ -339,7 +344,7 @@ public function updateCofigurableProductOptions(Varien_Event_Observer $observer)
*/
public function updateBundleProductOptions(Varien_Event_Observer $observer)
{
/* @var $weeeHelper Mage_Weee_Helper_Data */
/* @var Mage_Weee_Helper_Data $weeeHelper */
$weeeHelper = Mage::helper('weee');
if (!$weeeHelper->isEnabled()) {
return $this;
Expand Down Expand Up @@ -389,9 +394,10 @@ public function updateBundleProductOptions(Varien_Event_Observer $observer)
*/
public function setSessionQuoteStore(Varien_Event_Observer $observer)
{
/* @var $weeeHelper Mage_Weee_Helper_Data */
/* @var Mage_Weee_Helper_Data $weeeHelper */
$weeeHelper = Mage::helper('weee');

/** @var Mage_Adminhtml_Model_Session_Quote $sessionQuote */
$sessionQuote = $observer->getEvent()->getSessionQuote();
if ($sessionQuote) {
$weeeHelper->setStore($sessionQuote->getStore());
Expand All @@ -400,4 +406,3 @@ public function setSessionQuoteStore(Varien_Event_Observer $observer)
return $this;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ public function insertProductData($product, $data)
return $this;
}
}

1 change: 0 additions & 1 deletion app/code/core/Mage/Weee/Model/Resource/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,3 @@ public function getProductDiscountPercent($productId, $websiteId, $customerGroup
return $this->_getReadAdapter()->fetchOne($select);
}
}

20 changes: 12 additions & 8 deletions app/code/core/Mage/Weee/Model/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

/**
* Model to calculate Weee amount
*
* @method Mage_Weee_Model_Resource_Tax _getResource()
* @method Mage_Weee_Model_Resource_Tax getResource()
*/
class Mage_Weee_Model_Tax extends Mage_Core_Model_Abstract
{
Expand Down Expand Up @@ -104,8 +107,8 @@ public function getWeeeAmount(
$billing = null,
$website = null,
$calculateTax = false,
$ignoreDiscount = false)
{
$ignoreDiscount = false
) {
$amount = 0;
$attributes = $this->getProductWeeeAttributes(
$product,
Expand Down Expand Up @@ -154,9 +157,9 @@ public function getWeeeTaxAttributeCodes($forceEnabled = false)
* Get Weee amounts associated with a product
*
* @param Mage_Catalog_Model_Product $product
* @param Mage_Customer_Model_Address_Abstract $shipping
* @param Mage_Customer_Model_Address_Abstract $billing
* @param mixed $website
* @param Mage_Sales_Model_Quote_Address $shipping
* @param Mage_Sales_Model_Quote_Address $billing
* @param int $website
* @param boolean $calculateTax
* @param boolean $ignoreDiscount
* @return array|\Varien_Object
Expand All @@ -167,8 +170,8 @@ public function getProductWeeeAttributes(
$billing = null,
$website = null,
$calculateTax = null,
$ignoreDiscount = false)
{
$ignoreDiscount = false
) {
$result = array();
$allWeee = $this->getWeeeTaxAttributeCodes();
if (!$allWeee) {
Expand Down Expand Up @@ -196,7 +199,8 @@ public function getProductWeeeAttributes(

if (!$currentPercent) {
$currentPercent = Mage::getSingleton('tax/calculation')->getRate(
$rateRequest->setProductClassId($product->getTaxClassId()));
$rateRequest->setProductClassId($product->getTaxClassId())
);
}

$discountPercent = 0;
Expand Down
Loading