AntonioLoiaconoDesign_CalculateDiscount - Version 1.1.0

Version Notes

- Fix of the calculation of the discount rate: more accurate calculation.
- Calculation of the discount rate is removed for "Not Visible Individually” products.

Download this release

Release Info

Developer alditalia
Extension AntonioLoiaconoDesign_CalculateDiscount
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.0 to 1.1.0

app/code/community/AntonioLoiaconoDesign/CalculateDiscount/Model/Observer.php CHANGED
@@ -14,7 +14,7 @@ class AntonioLoiaconoDesign_CalculateDiscount_Model_Observer
14
  'label' => 'Calculate Discount',
15
  'confirm' => $block->__('Are you sure you want to calculates discount of the selected listing(s)?'),
16
  'url' => $block->getUrl('adminhtml/calculatediscount/massCalculate', array(
17
- 'store' => Mage::app()->getRequest()->getParam('store')
18
  ))
19
  ));
20
  }
@@ -24,9 +24,8 @@ class AntonioLoiaconoDesign_CalculateDiscount_Model_Observer
24
  $product = $observer->getProduct();
25
  $discountAttribute = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/attributeofdiscount');
26
 
27
- if ($product->getFinalPrice() < $product->getPrice()) {
28
-
29
- $discountPer = floor(100 - ($product->getFinalPrice() / $product->getPrice()) * 100);
30
  $discountConditions = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/discountconditions');
31
  if ($discountConditions) {
32
  $discountConditions = unserialize($discountConditions);
@@ -48,7 +47,7 @@ class AntonioLoiaconoDesign_CalculateDiscount_Model_Observer
48
  Mage::getSingleton('catalog/product_action')->updateAttributes(array(
49
  $product->getId()
50
  ), array(
51
- $discountAttribute => $discountOption['value']
52
  ), 0);
53
  }
54
 
14
  'label' => 'Calculate Discount',
15
  'confirm' => $block->__('Are you sure you want to calculates discount of the selected listing(s)?'),
16
  'url' => $block->getUrl('adminhtml/calculatediscount/massCalculate', array(
17
+ 'store' => Mage::app()->getRequest()->getParam('store')
18
  ))
19
  ));
20
  }
24
  $product = $observer->getProduct();
25
  $discountAttribute = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/attributeofdiscount');
26
 
27
+ if ($product->getFinalPrice() < $product->getPrice() && $product->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE){
28
+ $discountPer = round(($product->getFinalPrice() / $product->getPrice() * 100), 0, PHP_ROUND_HALF_DOWN);
 
29
  $discountConditions = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/discountconditions');
30
  if ($discountConditions) {
31
  $discountConditions = unserialize($discountConditions);
47
  Mage::getSingleton('catalog/product_action')->updateAttributes(array(
48
  $product->getId()
49
  ), array(
50
+ $discountAttribute => $discountOption
51
  ), 0);
52
  }
53
 
app/code/community/AntonioLoiaconoDesign/CalculateDiscount/controllers/Adminhtml/CalculatediscountController.php CHANGED
@@ -14,10 +14,18 @@ class AntonioLoiaconoDesign_CalculateDiscount_Adminhtml_CalculatediscountControl
14
  $this->_getSession()->addError($this->__('Please select product(s).'));
15
  $this->_redirect('adminhtml/catalog_product/index');
16
  } else {
17
- try {
18
- $collection = Mage::getResourceModel('catalog/product_collection')->addFieldToFilter('entity_id', array(
19
- $productIds
20
- ))->addAttributeToSelect('*');
 
 
 
 
 
 
 
 
21
 
22
  foreach ($collection as $_product) {
23
 
@@ -26,7 +34,7 @@ class AntonioLoiaconoDesign_CalculateDiscount_Adminhtml_CalculatediscountControl
26
 
27
  if ($product->getFinalPrice() < $product->getPrice()) {
28
 
29
- $discountPer = floor(100 - ($product->getFinalPrice() / $product->getPrice()) * 100);
30
  $discountConditions = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/discountconditions');
31
  if ($discountConditions) {
32
  $discountConditions = unserialize($discountConditions);
@@ -48,7 +56,7 @@ class AntonioLoiaconoDesign_CalculateDiscount_Adminhtml_CalculatediscountControl
48
  Mage::getSingleton('catalog/product_action')->updateAttributes(array(
49
  $product->getId()
50
  ), array(
51
- $discountAttribute => $discountOption['value']
52
  ), 0);
53
  }
54
 
14
  $this->_getSession()->addError($this->__('Please select product(s).'));
15
  $this->_redirect('adminhtml/catalog_product/index');
16
  } else {
17
+
18
+ try {
19
+ $visibility = array(
20
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG,
21
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH,
22
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
23
+ );
24
+
25
+ $collection = Mage::getResourceModel('catalog/product_collection')
26
+ ->addFieldToFilter('entity_id', array($productIds))
27
+ ->addAttributeToSelect('*')
28
+ ->addAttributeToFilter('visibility', $visibility);
29
 
30
  foreach ($collection as $_product) {
31
 
34
 
35
  if ($product->getFinalPrice() < $product->getPrice()) {
36
 
37
+ $discountPer = round(($product->getFinalPrice() / $product->getPrice() * 100), 0, PHP_ROUND_HALF_DOWN);
38
  $discountConditions = Mage::getStoreConfig('antonioloiaconodesign_calculatediscount/general/discountconditions');
39
  if ($discountConditions) {
40
  $discountConditions = unserialize($discountConditions);
56
  Mage::getSingleton('catalog/product_action')->updateAttributes(array(
57
  $product->getId()
58
  ), array(
59
+ $discountAttribute => $discountOption
60
  ), 0);
61
  }
62
 
app/code/community/AntonioLoiaconoDesign/CalculateDiscount/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <AntonioLoiaconoDesign_CalculateDiscount>
5
- <version>1.0.0</version>
6
  </AntonioLoiaconoDesign_CalculateDiscount>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <AntonioLoiaconoDesign_CalculateDiscount>
5
+ <version>1.1.0</version>
6
  </AntonioLoiaconoDesign_CalculateDiscount>
7
  </modules>
8
  <global>
app/code/community/AntonioLoiaconoDesign/CalculateDiscount/etc/system.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <tabs>
4
  <antonioloiaconodesign translate="label" module="calculatediscount">
5
- <label>ANTONIOLOIACONODESIGN.IT</label>
6
  <sort_order>100</sort_order>
7
  </antonioloiaconodesign>
8
  </tabs>
2
  <config>
3
  <tabs>
4
  <antonioloiaconodesign translate="label" module="calculatediscount">
5
+ <label>ALD</label>
6
  <sort_order>100</sort_order>
7
  </antonioloiaconodesign>
8
  </tabs>
package.xml CHANGED
@@ -1,18 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AntonioLoiaconoDesign_CalculateDiscount</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>The extension of the calculation discount will be useful to the one who will want to obtain a filter based on the percentage of discount in the frontend.</summary>
10
  <description>The extension of the calculation discount lets choose an attribute used for the discount. For each option dropdown of the attribute it is possible to associate a range of percentages that will be visible in frontend if the attribute makes itself filterable with results.</description>
11
- <notes>Fixed minor bugs</notes>
12
- <authors><author><name>Antonio Loiacono Design</name><user>antonioloiaconodesign</user><email>a.loiacono@live.it</email></author></authors>
13
- <date>2016-04-05</date>
14
- <time>08:51:55</time>
15
- <contents><target name="magecommunity"><dir name="AntonioLoiaconoDesign"><dir name="CalculateDiscount"><dir name="Block"><dir name="Config"><file name="DiscountConditions.php" hash="ea2c2594c7623d440d51daf3a3d3e210"/><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Discount.php" hash="04fdf4b428de3f987c282a1dde99f9d5"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CalculatediscountController.php" hash="577d106ba38fc5066b8feb447c8f35dc"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4034f1c2ab351864c50c09ae97dca679"/><file name="config.xml" hash="941fcc01980ffcf6815f21a31e7613be"/><file name="system.xml" hash="5f5cbd88bb1964e2d5a573d6d5ffaf56"/></dir><dir name="Helper"><file name="Data.php" hash="fcdff20954c5e5f57203236d3c90b204"/></dir><dir name="Model"><file name="Observer.php" hash="1cb74ee28e30d48766e624b0c9105e7a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="AntonioLoiaconoDesign_CalculateDiscount.xml" hash="31047778a163b19ed5c8b2bfeea2d337"/></dir></target></contents>
 
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AntonioLoiaconoDesign_CalculateDiscount</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>The extension of the calculation discount will be useful to the one who will want to obtain a filter based on the percentage of discount in the frontend.</summary>
10
  <description>The extension of the calculation discount lets choose an attribute used for the discount. For each option dropdown of the attribute it is possible to associate a range of percentages that will be visible in frontend if the attribute makes itself filterable with results.</description>
11
+ <notes>- Fix of the calculation of the discount rate: more accurate calculation.&#xD;
12
+ - Calculation of the discount rate is removed for "Not Visible Individually&#x201D; products.</notes>
13
+ <authors><author><name>alditalia</name><user>alditalia</user><email>a.loiacono@live.it</email></author></authors>
14
+ <date>2016-05-31</date>
15
+ <time>09:44:46</time>
16
+ <contents><target name="magecommunity"><dir name="AntonioLoiaconoDesign"><dir name="CalculateDiscount"><dir name="Block"><dir name="Config"><file name="DiscountConditions.php" hash="ea2c2594c7623d440d51daf3a3d3e210"/><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Discount.php" hash="04fdf4b428de3f987c282a1dde99f9d5"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CalculatediscountController.php" hash="d769f6e6daa6511e2900e44da0c0245e"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4034f1c2ab351864c50c09ae97dca679"/><file name="config.xml" hash="0225208bb8e164dee8130a6df5aa3693"/><file name="system.xml" hash="20cf733937cf47f94fcf4998fc879a4b"/></dir><dir name="Helper"><file name="Data.php" hash="fcdff20954c5e5f57203236d3c90b204"/></dir><dir name="Model"><file name="Observer.php" hash="9da3cfecb802896f9b2cb46786f8176d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="AntonioLoiaconoDesign_CalculateDiscount.xml" hash="31047778a163b19ed5c8b2bfeea2d337"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>