Version Notes
Initial Release
Download this release
Release Info
| Developer | p squared |
| Extension | Psquared_PriceFactor |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/Psquared/PriceFactor/Block/Product/Price.php +12 -0
- app/code/community/Psquared/PriceFactor/Helper/Data.php +5 -0
- app/code/community/Psquared/PriceFactor/Model/Observer.php +89 -0
- app/code/community/Psquared/PriceFactor/etc/config.xml +92 -0
- app/code/community/Psquared/PriceFactor/etc/system.xml +58 -0
- app/etc/modules/Psquared_PriceFactor.xml +10 -0
- app/locale/de_DE/Psquared_PriceFactor.csv +8 -0
- package.xml +27 -0
app/code/community/Psquared/PriceFactor/Block/Product/Price.php
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
//class Psquared_PriceFactor_Block_Product_Price extends Mage_Catalog_Block_Product_Price
|
| 4 |
+
class Psquared_PriceFactor_Block_Product_Price extends FireGento_GermanSetup_Block_Catalog_Product_Price
|
| 5 |
+
{
|
| 6 |
+
public function getDisplayMinimalPrice(){
|
| 7 |
+
if (Mage::getStoreConfig('catalog/price_factor/show_minimal_price') == 0){
|
| 8 |
+
return false;
|
| 9 |
+
}
|
| 10 |
+
return parent::getDisplayMinimalPrice();
|
| 11 |
+
}
|
| 12 |
+
}
|
app/code/community/Psquared/PriceFactor/Helper/Data.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Psquared_PriceFactor_Helper_Data extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
}
|
| 5 |
+
|
app/code/community/Psquared/PriceFactor/Model/Observer.php
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Psquared_PriceFactor_Model_Observer
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Modify prices on catagory page
|
| 7 |
+
*
|
| 8 |
+
* @param Varien_Event_Observer $observer
|
| 9 |
+
*/
|
| 10 |
+
public function catchCatalogProductCollectionLoadAfter($observer){
|
| 11 |
+
if (Mage::getStoreConfig('catalog/price_factor/enable_price_factor') == 1){
|
| 12 |
+
foreach ($observer->getEvent()->getCollection() as $product){
|
| 13 |
+
$this->_adjustProductPrice($product);
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Modify prices on product detail page
|
| 20 |
+
*
|
| 21 |
+
* @param Varien_Event_Observer $observer
|
| 22 |
+
*/
|
| 23 |
+
public function catchCatalogProductLoadAfter($observer){
|
| 24 |
+
if (Mage::getStoreConfig('catalog/price_factor/enable_price_factor') == 1){
|
| 25 |
+
$product = $observer->getEvent()->getProduct();
|
| 26 |
+
$this->_adjustProductPrice($product);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Detect store view change to clear cart
|
| 32 |
+
*
|
| 33 |
+
* @param Varien_Event_Observer $observer
|
| 34 |
+
*/
|
| 35 |
+
public function catchControllerActionPredispatch($observer){
|
| 36 |
+
if (Mage::getStoreConfig('catalog/price_factor/clear_cart_on_store_view_switch') == 1){
|
| 37 |
+
$fromStore = $_GET['___from_store'];
|
| 38 |
+
$store = $_GET['___store'];
|
| 39 |
+
if (!empty($fromStore) && !empty($store)) {
|
| 40 |
+
foreach(Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item){
|
| 41 |
+
Mage::getSingleton('checkout/cart')->removeItem($item->getId() )->save();
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Adjustment for price, special price, final price
|
| 49 |
+
*
|
| 50 |
+
* @param Mage_Catalog_Model_Product $product
|
| 51 |
+
* @return Mage_Catalog_Model_Product
|
| 52 |
+
*/
|
| 53 |
+
protected function _adjustProductPrice($product){
|
| 54 |
+
$adjustment = Mage::getStoreConfig('catalog/price_factor/price_factor');
|
| 55 |
+
|
| 56 |
+
$price = $product->getPrice();
|
| 57 |
+
$specialPrice = $product->getSpecialPrice();
|
| 58 |
+
$finalPrice = $product->getFinalPrice();
|
| 59 |
+
|
| 60 |
+
$finalPrice = $this->_adjustPrice($adjustment, $finalPrice);
|
| 61 |
+
$product->setFinalPrice($finalPrice);
|
| 62 |
+
|
| 63 |
+
//recalculate the special price, if this is set
|
| 64 |
+
if (!empty($specialPrice)){
|
| 65 |
+
$specialPrice = $this->_adjustPrice($adjustment, $specialPrice);
|
| 66 |
+
$product->setSpecialPrice($specialPrice);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
$price = $this->_adjustPrice($adjustment, $price);
|
| 70 |
+
$product->setPrice($price);
|
| 71 |
+
|
| 72 |
+
return $product;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Price value adjustment
|
| 77 |
+
*
|
| 78 |
+
* @param float $adjustment
|
| 79 |
+
* @param float $price
|
| 80 |
+
* @return float
|
| 81 |
+
*/
|
| 82 |
+
protected function _adjustPrice($adjustment, $price){
|
| 83 |
+
if ($adjustment > 0){
|
| 84 |
+
$price *= $adjustment;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
return $price;
|
| 88 |
+
}
|
| 89 |
+
}
|
app/code/community/Psquared/PriceFactor/etc/config.xml
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Psquared_PriceFactor>
|
| 5 |
+
<version>1.0.0</version>
|
| 6 |
+
</Psquared_PriceFactor>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<models>
|
| 10 |
+
<pricefactor>
|
| 11 |
+
<class>Psquared_PriceFactor_Model</class>
|
| 12 |
+
</pricefactor>
|
| 13 |
+
</models>
|
| 14 |
+
<helpers>
|
| 15 |
+
<pricefactor>
|
| 16 |
+
<class>Psquared_PriceFactor_Helper</class>
|
| 17 |
+
</pricefactor>
|
| 18 |
+
</helpers>
|
| 19 |
+
<blocks>
|
| 20 |
+
<pricefactor>
|
| 21 |
+
<class>Psquared_PriceFactor_Block</class>
|
| 22 |
+
</pricefactor>
|
| 23 |
+
<!-- Choose one of the following sections -->
|
| 24 |
+
<!-- 1st: Default - begin -->
|
| 25 |
+
<catalog>
|
| 26 |
+
<rewrite>
|
| 27 |
+
<product_price>Psquared_PriceFactor_Block_Product_Price</product_price>
|
| 28 |
+
</rewrite>
|
| 29 |
+
</catalog>
|
| 30 |
+
<!-- 1st: Default - end -->
|
| 31 |
+
<!-- 2nd: If the extension German Setup is installed - begin -->
|
| 32 |
+
<!-- <germansetup>
|
| 33 |
+
<rewrite>
|
| 34 |
+
<catalog_product_price>Psquared_PriceFactor_Block_Product_Price</catalog_product_price>
|
| 35 |
+
</rewrite>
|
| 36 |
+
</germansetup> -->
|
| 37 |
+
<!-- 2nd: If the extension German Setup is installed - end -->
|
| 38 |
+
</blocks>
|
| 39 |
+
</global>
|
| 40 |
+
<default>
|
| 41 |
+
<catalog>
|
| 42 |
+
<price_factor>
|
| 43 |
+
<enable_price_factor>0</enable_price_factor>
|
| 44 |
+
<price_factor>2</price_factor>
|
| 45 |
+
<show_minimal_price>0</show_minimal_price>
|
| 46 |
+
<clear_cart_on_store_view_switch>1</clear_cart_on_store_view_switch>
|
| 47 |
+
</price_factor>
|
| 48 |
+
</catalog>
|
| 49 |
+
</default>
|
| 50 |
+
<frontend>
|
| 51 |
+
<events>
|
| 52 |
+
<catalog_product_collection_load_after>
|
| 53 |
+
<observers>
|
| 54 |
+
<pricefactor>
|
| 55 |
+
<type>singleton</type>
|
| 56 |
+
<class>pricefactor/observer</class>
|
| 57 |
+
<method>catchCatalogProductCollectionLoadAfter</method>
|
| 58 |
+
</pricefactor>
|
| 59 |
+
</observers>
|
| 60 |
+
</catalog_product_collection_load_after>
|
| 61 |
+
<catalog_product_load_after>
|
| 62 |
+
<observers>
|
| 63 |
+
<pricefactor>
|
| 64 |
+
<type>singleton</type>
|
| 65 |
+
<class>pricefactor/observer</class>
|
| 66 |
+
<method>catchCatalogProductLoadAfter</method>
|
| 67 |
+
</pricefactor>
|
| 68 |
+
</observers>
|
| 69 |
+
</catalog_product_load_after>
|
| 70 |
+
<controller_action_predispatch>
|
| 71 |
+
<observers>
|
| 72 |
+
<pricefactor>
|
| 73 |
+
<type>singleton</type>
|
| 74 |
+
<class>pricefactor/observer</class>
|
| 75 |
+
<method>catchControllerActionPredispatch</method>
|
| 76 |
+
</pricefactor>
|
| 77 |
+
</observers>
|
| 78 |
+
</controller_action_predispatch>
|
| 79 |
+
</events>
|
| 80 |
+
</frontend>
|
| 81 |
+
<adminhtml>
|
| 82 |
+
<translate>
|
| 83 |
+
<modules>
|
| 84 |
+
<pricefactor>
|
| 85 |
+
<files>
|
| 86 |
+
<default>Psquared_PriceFactor.csv</default>
|
| 87 |
+
</files>
|
| 88 |
+
</pricefactor>
|
| 89 |
+
</modules>
|
| 90 |
+
</translate>
|
| 91 |
+
</adminhtml>
|
| 92 |
+
</config>
|
app/code/community/Psquared/PriceFactor/etc/system.xml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<sections>
|
| 4 |
+
<catalog translate="label" module="pricefactor">
|
| 5 |
+
<groups>
|
| 6 |
+
<price_factor translate="label">
|
| 7 |
+
<label>Price Factor</label>
|
| 8 |
+
<frontend_type>text</frontend_type>
|
| 9 |
+
<sort_order>410</sort_order>
|
| 10 |
+
<show_in_default>1</show_in_default>
|
| 11 |
+
<show_in_website>1</show_in_website>
|
| 12 |
+
<show_in_store>1</show_in_store>
|
| 13 |
+
<fields>
|
| 14 |
+
<enable_price_factor translate="label">
|
| 15 |
+
<label>Enable Price Factor</label>
|
| 16 |
+
<frontend_type>select</frontend_type>
|
| 17 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 18 |
+
<sort_order>10</sort_order>
|
| 19 |
+
<show_in_default>1</show_in_default>
|
| 20 |
+
<show_in_website>1</show_in_website>
|
| 21 |
+
<show_in_store>1</show_in_store>
|
| 22 |
+
<comment>This option enables a price factor for the product catalog.</comment>
|
| 23 |
+
</enable_price_factor>
|
| 24 |
+
<price_factor translate="label">
|
| 25 |
+
<label>Price Factor</label>
|
| 26 |
+
<frontend_type>text</frontend_type>
|
| 27 |
+
<sort_order>20</sort_order>
|
| 28 |
+
<show_in_default>1</show_in_default>
|
| 29 |
+
<show_in_website>1</show_in_website>
|
| 30 |
+
<show_in_store>1</show_in_store>
|
| 31 |
+
<comment>Decimal price factor which is multiplied with the product prices in the product catalog.</comment>
|
| 32 |
+
</price_factor>
|
| 33 |
+
<show_minimal_price translate="label">
|
| 34 |
+
<label>Show Minimal Price</label>
|
| 35 |
+
<frontend_type>select</frontend_type>
|
| 36 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 37 |
+
<sort_order>30</sort_order>
|
| 38 |
+
<show_in_default>1</show_in_default>
|
| 39 |
+
<show_in_website>1</show_in_website>
|
| 40 |
+
<show_in_store>1</show_in_store>
|
| 41 |
+
<comment>Disable this option if you use a price factor larger than 1 to disable the nonsensical presentation of the minimal price.</comment>
|
| 42 |
+
</show_minimal_price>
|
| 43 |
+
<clear_cart_on_store_view_switch translate="label">
|
| 44 |
+
<label>Clear Cart on Store View Switch</label>
|
| 45 |
+
<frontend_type>select</frontend_type>
|
| 46 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 47 |
+
<sort_order>40</sort_order>
|
| 48 |
+
<show_in_default>1</show_in_default>
|
| 49 |
+
<show_in_website>1</show_in_website>
|
| 50 |
+
<show_in_store>1</show_in_store>
|
| 51 |
+
<comment>Prevent wrong price factors on the products which already added to the cart.</comment>
|
| 52 |
+
</clear_cart_on_store_view_switch>
|
| 53 |
+
</fields>
|
| 54 |
+
</price_factor>
|
| 55 |
+
</groups>
|
| 56 |
+
</catalog>
|
| 57 |
+
</sections>
|
| 58 |
+
</config>
|
app/etc/modules/Psquared_PriceFactor.xml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Psquared_PriceFactor>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
<version>1.0.0</version>
|
| 8 |
+
</Psquared_PriceFactor>
|
| 9 |
+
</modules>
|
| 10 |
+
</config>
|
app/locale/de_DE/Psquared_PriceFactor.csv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Price Factor","Preisfaktor"
|
| 2 |
+
"Enable Price Factor","Preisfaktor aktivieren"
|
| 3 |
+
"Show Minimal Price","Zeige Minimalpreis"
|
| 4 |
+
"Clear Cart on Store View Switch","Leere Warenkorb bei Wechsel des Store Views"
|
| 5 |
+
"This option enables a price factor for the product catalog.","Diese Option aktiviert den Preisfaktor für den Produktkatalog."
|
| 6 |
+
"Decimal price factor which is multiplied with the product prices in the product catalog.","Preisfaktor als Dezimalzahl, welcher mit den Produktpreisen des Produktkatalogs multiplziert wird."
|
| 7 |
+
"Disable this option if you use a price factor larger than 1 to disable the nonsensical presentation of the minimal price.","Deaktiviere diese Option, wenn der Preisfaktor größer als 1 ist, um die unnötige Darstellung des Minimalpreises zu unterbinden."
|
| 8 |
+
"Prevent wrong price factors on the products which already added to the cart.","Vermeidet falsche Preisfaktoren bei Produkten, die bereits dem Warenkorb hinzugefügt wurden."
|
package.xml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Psquared_PriceFactor</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Define a price factor in the system configuration which is multiplied with all product prices.</summary>
|
| 10 |
+
<description>Define a price factor in the system configuration which is multiplied with all product prices. This is helpful to increase the price amount per store view. For example the german store view.
|
| 11 |
+

|
| 12 |
+
Features:
|
| 13 |
+
- Enable or disable price factor
|
| 14 |
+
- Define a price factor as integer or decimal. Values between 0 and 1 reduce the price. Values greater than 1 increase the final price.
|
| 15 |
+
- Disable the default minimal price in frontend for price factors lower than 1.
|
| 16 |
+
- Cart clearing to prevent wrong price factors by adding products and switching to another store view.
|
| 17 |
+

|
| 18 |
+
GitHub Repository:
|
| 19 |
+
https://github.com/patrickbaber/Psquared_PriceFactor</description>
|
| 20 |
+
<notes>Initial Release</notes>
|
| 21 |
+
<authors><author><name>p squared</name><user>p_squared</user><email>realityfforce@yahoo.de</email></author></authors>
|
| 22 |
+
<date>2013-04-12</date>
|
| 23 |
+
<time>10:16:04</time>
|
| 24 |
+
<contents><target name="magecommunity"><dir name="Psquared"><dir name="PriceFactor"><dir name="Block"><dir name="Product"><file name="Price.php" hash="5af988c0cfa1546302c5656512e8abe6"/></dir></dir><dir name="Helper"><file name="Data.php" hash="38561dbde0ffc73d964f8915f2d98c88"/></dir><dir name="Model"><file name="Observer.php" hash="7cf46bb5278223b436647ffdd68b0ca4"/></dir><dir name="etc"><file name="config.xml" hash="25dc66f7c7a675451e33ccefe1385f8a"/><file name="system.xml" hash="d81fefca824a94907d6f0d49c41a5fa9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Psquared_PriceFactor.xml" hash="be5ea6889215cc17c91ce60fed06d7e1"/></dir></target><target name="magelocale"><dir><dir name="de_DE"><file name="Psquared_PriceFactor.csv" hash="6f857928a8cd7f7f7a7c512116483c64"/></dir></dir></target></contents>
|
| 25 |
+
<compatible/>
|
| 26 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 27 |
+
</package>
|
