Spranks_ConfigurableTierPrices - Version 0.4.0

Version Notes

Also works with the manual order creation in the admin panel now

Download this release

Release Info

Developer Simon Sprankel
Extension Spranks_ConfigurableTierPrices
Version 0.4.0
Comparing to
See all releases


Code changes from version 0.0.3 to 0.4.0

app/code/community/Spranks/ConfigurableTierPrices/Helper/Admin.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Spranks_ConfigurableTierPrices_Helper_Admin extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ public function isAdmin()
7
+ {
8
+ if (Mage::app()->getStore()->isAdmin()) {
9
+ return true;
10
+ }
11
+ if (Mage::getDesign()->getArea() == 'adminhtml') {
12
+ return true;
13
+ }
14
+ return false;
15
+ }
16
+
17
+ }
app/code/community/Spranks/ConfigurableTierPrices/Model/Product/Type/Configurable/Price.php CHANGED
@@ -1,38 +1,8 @@
1
  <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category Mage
22
- * @package Mage_Catalog
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
 
27
- /**
28
- * Product type price model
29
- *
30
- * @category Mage
31
- * @package Mage_Catalog
32
- * @author Magento Core Team <core@magentocommerce.com>
33
- */
34
  class Spranks_ConfigurableTierPrices_Model_Product_Type_Configurable_Price extends Mage_Catalog_Model_Product_Type_Configurable_Price
35
  {
 
36
  /**
37
  * Get product final price
38
  *
@@ -40,91 +10,67 @@ class Spranks_ConfigurableTierPrices_Model_Product_Type_Configurable_Price exten
40
  * @param Mage_Catalog_Model_Product $product
41
  * @return double
42
  */
43
- public function getFinalPrice($qty=null, $product)
44
  {
45
- if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
46
- return $product->getCalculatedFinalPrice();
47
- }
48
-
49
  $finalPrice = parent::getFinalPrice($qty, $product);
50
-
51
  // if tier prices are defined, also adapt them to configurable products
52
  // example: if a shirt is available in red and black and if you buy
53
  // three or more the price is eight euro, you can also buy one red and
54
  // two black shirts and you will get the tier price of eight euro.
55
- // based on https://www.magentocommerce.com/boards/viewthread/10743/
56
- if ($product->getTierPriceCount() > 0) {
57
- $tierPrice = $this->calcConfigProductTierPricing($product);
58
- if($tierPrice > 0 && $tierPrice < $finalPrice)
59
- $finalPrice = $tierPrice;
60
- } else {
61
- // if there is no new tier price, do not apply attribute prices again
62
- return $finalPrice;
63
- }
64
-
65
- $product->getTypeInstance(true)
66
- ->setStoreFilter($product->getStore(), $product);
67
- $attributes = $product->getTypeInstance(true)
68
- ->getConfigurableAttributes($product);
69
-
70
- $selectedAttributes = array();
71
- if ($product->getCustomOption('attributes')) {
72
- $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
73
- }
74
-
75
- $basePrice = $finalPrice;
76
- foreach ($attributes as $attribute) {
77
- $attributeId = $attribute->getProductAttribute()->getId();
78
- $value = $this->_getValueByIndex(
79
- $attribute->getPrices() ? $attribute->getPrices() : array(),
80
- isset($selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] : null
81
- );
82
- $product->setParentId(true);
83
- if($value) {
84
- if($value['pricing_value'] != 0) {
85
- $finalPrice += $this->_calcSelectionPrice($value, $basePrice);
86
- }
87
  }
88
  }
89
- $product->setFinalPrice($finalPrice);
90
- return max(0, $product->getData('final_price'));
91
  }
92
-
93
- /**
94
- * Get product final price via configurable product's tier pricing structure.
95
- * Uses qty of parent item to determine price.
96
  *
97
  * @param Mage_Catalog_Model_Product $product
98
  * @return float
99
  */
100
- public function calcConfigProductTierPricing($product)
101
  {
102
- $tierPrice = 0;
103
 
104
- if ($items = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection()) {
105
- // map mapping the IDs of the parent products with the quantities of the corresponding simple products
106
- $idQuantities = array();
107
- // go through all products in the quote
108
- foreach ($items as $item) {
109
- if ($item->getParentItem())
110
- continue;
111
- // get the simple products ID
112
- $productModel = Mage::getModel('catalog/product');
113
- $id = $productModel->getIdBySku($item->getSku());
114
- // get the parent IDs
115
- $configurableProductModel = Mage::getModel('catalog/product_type_configurable');
116
- $parentIdArray = $configurableProductModel->getParentIdsByChild($id);
117
- // map the parent ID with the quantities of the simple products
118
- foreach ($parentIdArray as $parent)
119
- $idQuantities[$parent][] = $item->getQty();
120
- }
121
- // compute the total quantity of items of the configurable product
122
- if (array_key_exists($product->getId(), $idQuantities)) {
123
- $totalQty = array_sum($idQuantities[$product->getId()]);
124
- $tierPrice = $this->getTierPrice($totalQty, $product);
125
- }
126
- }
127
  return $tierPrice;
128
  }
129
 
 
 
 
 
 
 
 
 
 
130
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
 
3
  class Spranks_ConfigurableTierPrices_Model_Product_Type_Configurable_Price extends Mage_Catalog_Model_Product_Type_Configurable_Price
4
  {
5
+
6
  /**
7
  * Get product final price
8
  *
10
  * @param Mage_Catalog_Model_Product $product
11
  * @return double
12
  */
13
+ public function getFinalPrice($qty = null, $product)
14
  {
 
 
 
 
15
  $finalPrice = parent::getFinalPrice($qty, $product);
 
16
  // if tier prices are defined, also adapt them to configurable products
17
  // example: if a shirt is available in red and black and if you buy
18
  // three or more the price is eight euro, you can also buy one red and
19
  // two black shirts and you will get the tier price of eight euro.
20
+ // based on https://www.magentocommerce.com/boards/viewthread/10743/
21
+ if ($product->getTierPriceCount() > 0) {
22
+ $tierPrice = $this->_calcConfigProductTierPricing($product);
23
+ if ($tierPrice < $finalPrice) {
24
+ $finalPrice = $tierPrice;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
  }
27
+ return $finalPrice;
 
28
  }
29
+
30
+ /**
31
+ * Get product final price via configurable product's tier pricing structure.
32
+ * Uses qty of parent item to determine price.
33
  *
34
  * @param Mage_Catalog_Model_Product $product
35
  * @return float
36
  */
37
+ protected function _calcConfigProductTierPricing($product)
38
  {
39
+ $tierPrice = PHP_INT_MAX;
40
 
41
+ if ($items = $this->_getAllVisibleItems()) {
42
+ // map mapping the IDs of the parent products with the quantities of the corresponding simple products
43
+ $idQuantities = array();
44
+ // go through all products in the quote
45
+ foreach ($items as $item) {
46
+ if ($item->getParentItem())
47
+ continue;
48
+ // get the simple products ID
49
+ $productModel = Mage::getModel('catalog/product');
50
+ $id = $productModel->getIdBySku($item->getSku());
51
+ // get the parent IDs
52
+ $configurableProductModel = Mage::getModel('catalog/product_type_configurable');
53
+ $parentIdArray = $configurableProductModel->getParentIdsByChild($id);
54
+ // map the parent ID with the quantities of the simple products
55
+ foreach ($parentIdArray as $parent)
56
+ $idQuantities[$parent][] = $item->getQty();
57
+ }
58
+ // compute the total quantity of items of the configurable product
59
+ if (array_key_exists($product->getId(), $idQuantities)) {
60
+ $totalQty = array_sum($idQuantities[$product->getId()]);
61
+ $tierPrice = parent::getFinalPrice($totalQty, $product);
62
+ }
63
+ }
64
  return $tierPrice;
65
  }
66
 
67
+ protected function _getAllVisibleItems()
68
+ {
69
+ if (Mage::helper('spranks_configurabletierprices/admin')->isAdmin()) {
70
+ return Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
71
+ } else {
72
+ return Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
73
+ }
74
+ }
75
+
76
  }
app/code/community/Spranks/ConfigurableTierPrices/etc/config.xml CHANGED
@@ -1,17 +1,22 @@
1
  <?xml version="1.0"?>
2
  <config>
3
- <modules>
4
- <Spranks_ConfigurableTierPrices>
5
- <version>0.1.0</version>
6
- </Spranks_ConfigurableTierPrices>
7
- </modules>
8
- <global>
9
- <models>
10
- <catalog>
11
- <rewrite>
12
- <product_type_configurable_price>Spranks_ConfigurableTierPrices_Model_Product_Type_Configurable_Price</product_type_configurable_price>
13
- </rewrite>
14
- </catalog>
15
- </models>
16
- </global>
17
- </config>
 
 
 
 
 
1
  <?xml version="1.0"?>
2
  <config>
3
+ <modules>
4
+ <Spranks_ConfigurableTierPrices>
5
+ <version>0.4.0</version>
6
+ </Spranks_ConfigurableTierPrices>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <catalog>
11
+ <rewrite>
12
+ <product_type_configurable_price>Spranks_ConfigurableTierPrices_Model_Product_Type_Configurable_Price</product_type_configurable_price>
13
+ </rewrite>
14
+ </catalog>
15
+ </models>
16
+ <helpers>
17
+ <spranks_configurabletierprices>
18
+ <class>Spranks_ConfigurableTierPrices_Helper</class>
19
+ </spranks_configurabletierprices>
20
+ </helpers>
21
+ </global>
22
+ </config>
package.xml CHANGED
@@ -1,41 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Spranks_ConfigurableTierPrices</name>
4
- <version>0.0.3</version>
5
  <stability>stable</stability>
6
- <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This module changes the way Magento calculates tier prices of configurable products.</summary>
10
- <description>Spranks_ConfigurableTierPrices&#xD;
11
- =========================&#xD;
12
- This Magento module changes the way Magento calculates tier prices of configurable products. You can now add different variants of a configurable product to the cart and you will get the tier price for the total quantity of all variants in the cart.&#xD;
13
- &#xD;
14
- Example&#xD;
15
- ------------&#xD;
16
- There is a configurable product "football" and there are two corresponding variants "white" and "orange". The price for each football is 20 EUR. If you buy five or more, you only have to pay 18 EUR each. Now you add three white and two orange footballs to your cart. What would you expect? You would like to have the footballs for 18 EUR each, right? Not with Magento. Unfortunately, Magento will charge you 20 EUR each. Fortunately, you can install the module Spranks_ConfigurableTierPrices and 18 EUR will be charged as expected.&#xD;
17
- &#xD;
18
- Requirements&#xD;
19
- -------------------&#xD;
20
- The module has been tested with Magento 1.4.2, 1.5.1 and 1.6.2. If you have installed Spranks_ConfigurableTierPrices before, please delete the following files and folders from your Magento root before you install this extension:&#xD;
21
- &#xD;
22
- * app/etc/modules/Spranks_ConfigurableTierPrices.xml&#xD;
23
- * app/code/local/Spranks/ConfigurableTierPrices&#xD;
24
- &#xD;
25
- Changelog&#xD;
26
- ---------------&#xD;
27
- 0.0.2&#xD;
28
- * changed code pool from local to community&#xD;
29
- * FIXED wrong price if no tier price is defined&#xD;
30
- * FIXED wrong price if a special price is defined&#xD;
31
- &#xD;
32
- 0.0.1&#xD;
33
- * initial release on [www.coderblog.de](http://www.coderblog.de/magento-tier-prices-for-configurable-products)</description>
34
- <notes>Repackaged extension as stable</notes>
35
- <authors><author><name>Simon Sprankel</name><user>auto-converted</user><email>simonsprankel@googlemail.com</email></author></authors>
36
- <date>2012-10-01</date>
37
- <time>07:25:56</time>
38
- <contents><target name="magecommunity"><dir name="Spranks"><dir name="ConfigurableTierPrices"><dir name="Model"><dir name="Product"><dir name="Type"><dir name="Configurable"><file name="Price.php" hash="a6a019ea5f4d20782851f9eb75b38d95"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="1aded0470fe31749945e459b7e2f5414"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Spranks_ConfigurableTierPrices.xml" hash="8a3f62990ce094cb7e7e6313b66d5d51"/></dir></target></contents>
39
  <compatible/>
40
- <dependencies/>
41
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Spranks_ConfigurableTierPrices</name>
4
+ <version>0.4.0</version>
5
  <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This module changes the way Magento calculates tier prices of configurable products.</summary>
10
+ <description>This Magento module changes the way Magento calculates tier prices of configurable products. You can now add different variants of a configurable product to the cart and you will get the tier price for the total quantity of all variants in the cart.</description>
11
+ <notes>Also works with the manual order creation in the admin panel now</notes>
12
+ <authors><author><name>Simon Sprankel</name><user>spranks</user><email>simonsprankel@gmail.com</email></author></authors>
13
+ <date>2013-06-15</date>
14
+ <time>12:51:01</time>
15
+ <contents><target name="magecommunity"><dir name="Spranks"><dir name="ConfigurableTierPrices"><dir name="Helper"><file name="Admin.php" hash="7ec6839ca9c1fa032d493eaba60e391a"/></dir><dir name="Model"><dir name="Product"><dir name="Type"><dir name="Configurable"><file name="Price.php" hash="fe9bdd8c4cb2ce442b3c8e6ad4d8c4ec"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="86aa5511a60f71b23f941865580ad310"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Spranks_ConfigurableTierPrices.xml" hash="8a3f62990ce094cb7e7e6313b66d5d51"/></dir></target></contents>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>