Spranks_ConfigurableTierPrices - Version 2.1.0

Version Notes

possibility to disable the extension from the admin panel, possibility to disable the extension for specific categories, possibility to disable the extension for specific products

Download this release

Release Info

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


Code changes from version 2.0.0 to 2.1.0

app/code/community/Spranks/ConfigurableTierPrices/Helper/Admin.php DELETED
@@ -1,18 +0,0 @@
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
-
15
- return false;
16
- }
17
-
18
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Spranks/ConfigurableTierPrices/Helper/Data.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Spranks_ConfigurableTierPrices_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ const XML_PATH_IS_ENABLED = 'spranks_configurabletierprices/general/is_enabled';
7
+ const XML_PATH_DISABLED_FOR_CATEGORY = 'spranks_configurabletierprices/general/disabled_for_category';
8
+
9
+ // attribute code length must be less than 30 symbols!
10
+ const ATTRIBUTE_DISABLED_FOR_PRODUCT = 'configtierprices_disabled';
11
+
12
+ public function isAdmin()
13
+ {
14
+ if (Mage::app()->getStore()->isAdmin()) {
15
+ return true;
16
+ }
17
+ if (Mage::getDesign()->getArea() == 'adminhtml') {
18
+ return true;
19
+ }
20
+
21
+ return false;
22
+ }
23
+
24
+ public function isExtensionEnabled()
25
+ {
26
+ return Mage::getStoreConfigFlag(self::XML_PATH_IS_ENABLED);
27
+ }
28
+
29
+ public function isProductInDisabledCategory(Mage_Catalog_Model_Product $product)
30
+ {
31
+ $disabledCategories = explode(',', Mage::getStoreConfig(self::XML_PATH_DISABLED_FOR_CATEGORY));
32
+ $productCategories = $product->getAvailableInCategories();
33
+ if (count(array_intersect($disabledCategories, $productCategories)) > 0) {
34
+ return true;
35
+ }
36
+
37
+ return false;
38
+ }
39
+
40
+ public function isExtensionDisabledForProduct(Mage_Catalog_Model_Product $product)
41
+ {
42
+ // get the product attribute directly, because it may not be loaded
43
+ $configtierpricesDisabled = Mage::getResourceModel('catalog/product')->getAttributeRawValue(
44
+ $product->getId(), self::ATTRIBUTE_DISABLED_FOR_PRODUCT, Mage::app()->getStore()
45
+ );
46
+ if ($configtierpricesDisabled) {
47
+ return true;
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ }
app/code/community/Spranks/ConfigurableTierPrices/Model/Observer.php CHANGED
@@ -13,6 +13,11 @@ class Spranks_ConfigurableTierPrices_Model_Observer
13
  public function catalogProductGetFinalPrice(Varien_Event_Observer $observer)
14
  {
15
  $product = $observer->getProduct();
 
 
 
 
 
16
  // do not calculate tier prices based on cart items on product page
17
  // see https://github.com/sprankhub/Spranks_ConfigurableTierPrices/issues/14
18
  if (Mage::registry('current_product') || ! $product->isConfigurable()) {
@@ -72,7 +77,7 @@ class Spranks_ConfigurableTierPrices_Model_Observer
72
  */
73
  private function _getAllVisibleItems()
74
  {
75
- if (Mage::helper('spranks_configurabletierprices/admin')->isAdmin()) {
76
  return Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
77
  } else {
78
  return Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
13
  public function catalogProductGetFinalPrice(Varien_Event_Observer $observer)
14
  {
15
  $product = $observer->getProduct();
16
+ if (!Mage::helper('spranks_configurabletierprices')->isExtensionEnabled()
17
+ || Mage::helper('spranks_configurabletierprices')->isProductInDisabledCategory($product)
18
+ || Mage::helper('spranks_configurabletierprices')->isExtensionDisabledForProduct($product)) {
19
+ return $this;
20
+ }
21
  // do not calculate tier prices based on cart items on product page
22
  // see https://github.com/sprankhub/Spranks_ConfigurableTierPrices/issues/14
23
  if (Mage::registry('current_product') || ! $product->isConfigurable()) {
77
  */
78
  private function _getAllVisibleItems()
79
  {
80
+ if (Mage::helper('spranks_configurabletierprices')->isAdmin()) {
81
  return Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
82
  } else {
83
  return Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
app/code/community/Spranks/ConfigurableTierPrices/Model/System/Config/Source/Category.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Source model for all categories except the root category.
4
+ */
5
+ class Spranks_ConfigurableTierPrices_Model_System_Config_Source_Category
6
+ {
7
+
8
+ public function toOptionArray()
9
+ {
10
+ $collection = Mage::getResourceModel('catalog/category_collection');
11
+
12
+ $collection->addAttributeToSelect('name')
13
+ ->addFieldToFilter('level', array('gteq' => 1))
14
+ ->load();
15
+
16
+ $options = array();
17
+
18
+ $options[] = array(
19
+ 'label' => Mage::helper('spranks_configurabletierprices')->__('-- Disable for no Category --'),
20
+ 'value' => ''
21
+ );
22
+
23
+ foreach ($collection as $category) {
24
+ $label = $category->getName();
25
+ // pad, so that categories' nesting structure is displayed correctly
26
+ $padLength = ($category->getLevel() - 1) * 2 + strlen($label);
27
+ $label = str_pad($label, $padLength, '-', STR_PAD_LEFT);
28
+ $options[] = array(
29
+ 'label' => $label,
30
+ 'value' => $category->getId()
31
+ );
32
+ }
33
+
34
+ return $options;
35
+ }
36
+
37
+ }
app/code/community/Spranks/ConfigurableTierPrices/Test/Config/Main/expectations/testModuleConfig.yaml CHANGED
@@ -1,3 +1,3 @@
1
  module:
2
- version: 2.0.0
3
  code_pool: community
1
  module:
2
+ version: 2.1.0
3
  code_pool: community
app/code/community/Spranks/ConfigurableTierPrices/etc/adminhtml.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <spranks_configurabletierprices translate="title">
8
+ <title>Configurable Tier Prices</title>
9
+ <sort_order>510</sort_order>
10
+ </spranks_configurabletierprices>
11
+ <system>
12
+ <children>
13
+ <config>
14
+ <children>
15
+ <spranks_configurabletierprices translate="title">
16
+ <title>Configurable Tier Prices Settings</title>
17
+ </spranks_configurabletierprices>
18
+ </children>
19
+ </config>
20
+ </children>
21
+ </system>
22
+ </children>
23
+ </admin>
24
+ </resources>
25
+ </acl>
26
+ </config>
app/code/community/Spranks/ConfigurableTierPrices/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Spranks_ConfigurableTierPrices>
5
- <version>2.0.0</version>
6
  </Spranks_ConfigurableTierPrices>
7
  </modules>
8
  <global>
@@ -11,6 +11,14 @@
11
  <class>Spranks_ConfigurableTierPrices_Model</class>
12
  </spranks_configurabletierprices>
13
  </models>
 
 
 
 
 
 
 
 
14
  <helpers>
15
  <spranks_configurabletierprices>
16
  <class>Spranks_ConfigurableTierPrices_Helper</class>
@@ -27,6 +35,25 @@
27
  </catalog_product_get_final_price>
28
  </events>
29
  </global>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  <phpunit>
31
  <suite>
32
  <modules>
2
  <config>
3
  <modules>
4
  <Spranks_ConfigurableTierPrices>
5
+ <version>2.1.0</version>
6
  </Spranks_ConfigurableTierPrices>
7
  </modules>
8
  <global>
11
  <class>Spranks_ConfigurableTierPrices_Model</class>
12
  </spranks_configurabletierprices>
13
  </models>
14
+ <resources>
15
+ <spranks_configurabletierprices_setup>
16
+ <setup>
17
+ <module>Spranks_ConfigurableTierPrices</module>
18
+ <class>Mage_Catalog_Model_Resource_Setup</class>
19
+ </setup>
20
+ </spranks_configurabletierprices_setup>
21
+ </resources>
22
  <helpers>
23
  <spranks_configurabletierprices>
24
  <class>Spranks_ConfigurableTierPrices_Helper</class>
35
  </catalog_product_get_final_price>
36
  </events>
37
  </global>
38
+ <adminhtml>
39
+ <translate>
40
+ <modules>
41
+ <Spranks_ConfigurableTierPrices>
42
+ <files>
43
+ <default>Spranks_ConfigurableTierPrices.csv</default>
44
+ </files>
45
+ </Spranks_ConfigurableTierPrices>
46
+ </modules>
47
+ </translate>
48
+ </adminhtml>
49
+ <default>
50
+ <spranks_configurabletierprices>
51
+ <general>
52
+ <is_enabled>1</is_enabled>
53
+ <disabled_for_category/>
54
+ </general>
55
+ </spranks_configurabletierprices>
56
+ </default>
57
  <phpunit>
58
  <suite>
59
  <modules>
app/code/community/Spranks/ConfigurableTierPrices/etc/system.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <spranks translate="label">
5
+ <label>Spranks Extensions</label>
6
+ <sort_order>301</sort_order>
7
+ </spranks>
8
+ </tabs>
9
+ <sections>
10
+ <spranks_configurabletierprices translate="label">
11
+ <tab>spranks</tab>
12
+ <label>Configurable Tier Prices</label>
13
+ <sort_order>30</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <general translate="label" module="spranks_configurabletierprices">
19
+ <label>General Settings</label>
20
+ <sort_order>10</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <fields>
25
+ <is_enabled translate="label">
26
+ <label>Enable Extension</label>
27
+ <frontend_type>select</frontend_type>
28
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
29
+ <sort_order>20</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </is_enabled>
34
+ <disabled_for_category>
35
+ <label>Disable Extension for the Following Categories</label>
36
+ <frontend_type>multiselect</frontend_type>
37
+ <source_model>spranks_configurabletierprices/system_config_source_category</source_model>
38
+ <sort_order>30</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </disabled_for_category>
43
+ </fields>
44
+ </general>
45
+ </groups>
46
+ </spranks_configurabletierprices>
47
+ </sections>
48
+ </config>
app/code/community/Spranks/ConfigurableTierPrices/sql/spranks_configurabletierprices_setup/upgrade-2.0.0-2.1.0.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Mage_Catalog_Model_Resource_Setup $installer */
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+
7
+ $attributeCode = Spranks_ConfigurableTierPrices_Helper_Data::ATTRIBUTE_DISABLED_FOR_PRODUCT;
8
+ $installer->addAttribute(
9
+ Mage_Catalog_Model_Product::ENTITY, $attributeCode, array(
10
+ 'label' => 'Disable Spranks Configurable Tier Prices',
11
+ 'group' => 'General',
12
+ 'type' => 'int',
13
+ 'input' => 'select',
14
+ 'source' => 'eav/entity_attribute_source_boolean',
15
+ 'backend' => 'catalog/product_attribute_backend_boolean',
16
+ 'frontend' => '',
17
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
18
+ 'required' => false,
19
+ 'default' => false,
20
+ 'user_defined' => false,
21
+ 'filterable_in_search' => false,
22
+ 'is_configurable' => false,
23
+ 'used_in_product_listing' => true
24
+ )
25
+ );
26
+
27
+ $installer->endSetup();
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Spranks_ConfigurableTierPrices</name>
4
- <version>2.0.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>Removed rewrite, now only uses events, implemented unit tests, dropped support for &lt; 1.7</notes>
12
  <authors><author><name>Simon Sprankel</name><user>spranks</user><email>simonsprankel@gmail.com</email></author></authors>
13
- <date>2014-12-06</date>
14
- <time>13:04:38</time>
15
- <contents><target name="magecommunity"><dir name="Spranks"><dir name="ConfigurableTierPrices"><dir name="Helper"><file name="Admin.php" hash="719aeec97e6a35b4bea91d82ad39aa42"/></dir><dir name="Model"><file name="Observer.php" hash="20ffa6c695961f316e70d8c2e311be51"/></dir><dir name="Test"><dir name="Config"><dir name="Main"><dir name="expectations"><file name="testModuleConfig.yaml" hash="a0728d3db36c6cd79759b78a804ae122"/></dir></dir><file name="Main.php" hash="487596affa2958576eb8f8cf8b4ade5f"/></dir><dir name="Model"><dir name="ObserverTest"><dir name="fixtures"><file name="createProducts.yaml" hash="52d581525f75a2ffc86b2a361eae8c0a"/></dir></dir><file name="ObserverTest.php" hash="268a3b1275dfe621af53c8883199839c"/></dir></dir><dir name="etc"><file name="config.xml" hash="ff110f81978feff76fb25517ee084464"/></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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Spranks_ConfigurableTierPrices</name>
4
+ <version>2.1.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>possibility to disable the extension from the admin panel, possibility to disable the extension for specific categories, possibility to disable the extension for specific products</notes>
12
  <authors><author><name>Simon Sprankel</name><user>spranks</user><email>simonsprankel@gmail.com</email></author></authors>
13
+ <date>2015-01-06</date>
14
+ <time>16:00:49</time>
15
+ <contents><target name="magecommunity"><dir name="Spranks"><dir name="ConfigurableTierPrices"><dir name="Helper"><file name="Data.php" hash="728524d770822272ae4ca69a77355c02"/></dir><dir name="Model"><file name="Observer.php" hash="bd0903a15b26d67a83d225b25ad9b927"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Category.php" hash="c63b3b1177f2fb1aa08070b156fe9fff"/></dir></dir></dir></dir><dir name="Test"><dir name="Config"><dir name="Main"><dir name="expectations"><file name="testModuleConfig.yaml" hash="74b1f280637c647eb6fb328406a9d61a"/></dir></dir><file name="Main.php" hash="487596affa2958576eb8f8cf8b4ade5f"/></dir><dir name="Model"><dir name="ObserverTest"><dir name="fixtures"><file name="createProducts.yaml" hash="52d581525f75a2ffc86b2a361eae8c0a"/></dir></dir><file name="ObserverTest.php" hash="268a3b1275dfe621af53c8883199839c"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f259c4c957a1679ffc132eecdcde9ef0"/><file name="config.xml" hash="f4d0c66218a52e1523b698b353c557d8"/><file name="system.xml" hash="956eb2b624f8d39b5fb6d9ce02077866"/></dir><dir name="sql"><dir name="spranks_configurabletierprices_setup"><file name="upgrade-2.0.0-2.1.0.php" hash="864b04c416e67615c3262185e1b7539c"/></dir></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>