Version Notes
First release
Download this release
Release Info
| Developer | Peter Jaap Blaakmeer |
| Extension | Elgentos_Tierpercentages |
| Version | 0.1.0 |
| Comparing to | |
| See all releases | |
Version 0.1.0
- app/code/local/Elgentos/Tierpercentages/Block/Adminhtml/Catalog/Product/Edit/Tab/Price/Tier.php +9 -0
- app/code/local/Elgentos/Tierpercentages/Helper/Data.php +5 -0
- app/code/local/Elgentos/Tierpercentages/Model/Mysql4/Setup.php +6 -0
- app/code/local/Elgentos/Tierpercentages/Model/Product/Attribute/Backend/Tierprice.php +77 -0
- app/code/local/Elgentos/Tierpercentages/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php +34 -0
- app/code/local/Elgentos/Tierpercentages/etc/config.xml +60 -0
- app/code/local/Elgentos/Tierpercentages/sql/tierpercentages_setup/mysql4-install-0.1.0.php +5 -0
- app/design/adminhtml/default/default/template/tierpercentages/tier.phtml +178 -0
- app/etc/modules/Elgentos_Tierpercentages.xml +9 -0
- js/elgentos/tierpercentages.js +43 -0
- package.xml +18 -0
app/code/local/Elgentos/Tierpercentages/Block/Adminhtml/Catalog/Product/Edit/Tab/Price/Tier.php
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Elgentos_Tierpercentages_Block_Adminhtml_Catalog_Product_Edit_Tab_Price_Tier extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier
|
| 4 |
+
{
|
| 5 |
+
public function __construct()
|
| 6 |
+
{
|
| 7 |
+
$this->setTemplate('tierpercentages/tier.phtml');
|
| 8 |
+
}
|
| 9 |
+
}
|
app/code/local/Elgentos/Tierpercentages/Helper/Data.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Elgentos_Tierpercentages_Helper_Data extends Mage_Core_Helper_Abstract {
|
| 4 |
+
|
| 5 |
+
}
|
app/code/local/Elgentos/Tierpercentages/Model/Mysql4/Setup.php
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Elgentos_Tierpercentages_Model_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
}
|
app/code/local/Elgentos/Tierpercentages/Model/Product/Attribute/Backend/Tierprice.php
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Elgentos_Tierpercentages_Model_Product_Attribute_Backend_Tierprice extends Mage_Catalog_Model_Product_Attribute_Backend_Tierprice
|
| 3 |
+
{
|
| 4 |
+
public function afterSave($object)
|
| 5 |
+
{
|
| 6 |
+
$this->_getResource()->deleteProductPrices($object, $this->getAttribute());
|
| 7 |
+
$tierPrices = $object->getData($this->getAttribute()->getName());
|
| 8 |
+
|
| 9 |
+
if (!is_array($tierPrices)) {
|
| 10 |
+
return $this;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
$prices = array();
|
| 14 |
+
foreach ($tierPrices as $tierPrice) {
|
| 15 |
+
if (empty($tierPrice['price_qty']) || !isset($tierPrice['price']) || !empty($tierPrice['delete'])) {
|
| 16 |
+
continue;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
$useForAllGroups = $tierPrice['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL;
|
| 20 |
+
$customerGroupId = !$useForAllGroups ? $tierPrice['cust_group'] : 0;
|
| 21 |
+
$priceKey = join('-', array(
|
| 22 |
+
$tierPrice['website_id'],
|
| 23 |
+
intval($useForAllGroups),
|
| 24 |
+
$customerGroupId,
|
| 25 |
+
$tierPrice['price_qty']
|
| 26 |
+
));
|
| 27 |
+
//Add new column "percentage"
|
| 28 |
+
$prices[$priceKey] = array(
|
| 29 |
+
'website_id' => $tierPrice['website_id'],
|
| 30 |
+
'all_groups' => intval($useForAllGroups),
|
| 31 |
+
'customer_group_id' => $customerGroupId,
|
| 32 |
+
'qty' => $tierPrice['price_qty'],
|
| 33 |
+
'value' => $tierPrice['price'],
|
| 34 |
+
'percentage' => $tierPrice['percentage'],
|
| 35 |
+
);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if ($this->getAttribute()->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE) {
|
| 39 |
+
if ($storeId = $object->getStoreId()) {
|
| 40 |
+
$websites = array(Mage::app()->getStore($storeId)->getWebsite());
|
| 41 |
+
}
|
| 42 |
+
else {
|
| 43 |
+
$websites = Mage::app()->getWebsites();
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
$baseCurrency = Mage::app()->getBaseCurrencyCode();
|
| 47 |
+
$rates = $this->_getWebsiteRates();
|
| 48 |
+
foreach ($websites as $website) {
|
| 49 |
+
/* @var $website Mage_Core_Model_Website */
|
| 50 |
+
if (!is_array($object->getWebsiteIds()) || !in_array($website->getId(), $object->getWebsiteIds())) {
|
| 51 |
+
continue;
|
| 52 |
+
}
|
| 53 |
+
if ($rates[$website->getId()]['code'] != $baseCurrency) {
|
| 54 |
+
foreach ($prices as $data) {
|
| 55 |
+
$priceKey = join('-', array(
|
| 56 |
+
$website->getId(),
|
| 57 |
+
$data['all_groups'],
|
| 58 |
+
$data['customer_group_id'],
|
| 59 |
+
$data['qty']
|
| 60 |
+
));
|
| 61 |
+
if (!isset($prices[$priceKey])) {
|
| 62 |
+
$prices[$priceKey] = $data;
|
| 63 |
+
$prices[$priceKey]['website_id'] = $website->getId();
|
| 64 |
+
$prices[$priceKey]['value'] = $data['value'] * $rates[$website->getId()]['rate'];
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
foreach ($prices as $data) {
|
| 72 |
+
$this->_getResource()->insertProductPrice($object, $data);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return $this;
|
| 76 |
+
}
|
| 77 |
+
}
|
app/code/local/Elgentos/Tierpercentages/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Elgentos_Tierpercentages_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice
|
| 4 |
+
{
|
| 5 |
+
public function loadPriceData($productId, $websiteId = null)
|
| 6 |
+
{
|
| 7 |
+
$adapter = $this->_getReadAdapter();
|
| 8 |
+
|
| 9 |
+
$columns = array(
|
| 10 |
+
'price_id' => $this->getIdFieldName(),
|
| 11 |
+
'website_id' => 'website_id',
|
| 12 |
+
'all_groups' => 'all_groups',
|
| 13 |
+
'cust_group' => 'customer_group_id',
|
| 14 |
+
'price_qty' => 'qty',
|
| 15 |
+
'price' => 'value',
|
| 16 |
+
'percentage' => 'percentage',
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
$select = $adapter->select()
|
| 20 |
+
->from($this->getMainTable(), $columns)
|
| 21 |
+
->where('entity_id=?', $productId)
|
| 22 |
+
->order('qty');
|
| 23 |
+
|
| 24 |
+
if (!is_null($websiteId)) {
|
| 25 |
+
if ($websiteId == '0') {
|
| 26 |
+
$select->where('website_id = ?', $websiteId);
|
| 27 |
+
} else {
|
| 28 |
+
$select->where('website_id IN(?)', array(0, $websiteId));
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return $adapter->fetchAll($select);
|
| 33 |
+
}
|
| 34 |
+
}
|
app/code/local/Elgentos/Tierpercentages/etc/config.xml
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Elgentos_Tierpercentages>
|
| 5 |
+
<version>0.1.0</version>
|
| 6 |
+
</Elgentos_Tierpercentages>
|
| 7 |
+
</modules>
|
| 8 |
+
|
| 9 |
+
<adminhtml>
|
| 10 |
+
<layout>
|
| 11 |
+
<updates>
|
| 12 |
+
<tierpercentages>
|
| 13 |
+
<file>tierpercentages.xml</file>
|
| 14 |
+
</tierpercentages>
|
| 15 |
+
</updates>
|
| 16 |
+
</layout>
|
| 17 |
+
</adminhtml>
|
| 18 |
+
|
| 19 |
+
<global>
|
| 20 |
+
<blocks>
|
| 21 |
+
<tierpercentages>
|
| 22 |
+
<class>Elgentos_Tierpercentages_Block</class>
|
| 23 |
+
</tierpercentages>
|
| 24 |
+
<adminhtml>
|
| 25 |
+
<rewrite>
|
| 26 |
+
<catalog_product_edit_tab_price_tier>Elgentos_Tierpercentages_Block_Adminhtml_Catalog_Product_Edit_Tab_Price_Tier</catalog_product_edit_tab_price_tier>
|
| 27 |
+
</rewrite>
|
| 28 |
+
</adminhtml>
|
| 29 |
+
</blocks>
|
| 30 |
+
<models>
|
| 31 |
+
<tierpercentages>
|
| 32 |
+
<class>Elgentos_Tierpercentages_Model</class>
|
| 33 |
+
</tierpercentages>
|
| 34 |
+
<catalog>
|
| 35 |
+
<rewrite>
|
| 36 |
+
<product_attribute_backend_tierprice>Elgentos_Tierpercentages_Model_Product_Attribute_Backend_Tierprice</product_attribute_backend_tierprice>
|
| 37 |
+
</rewrite>
|
| 38 |
+
</catalog>
|
| 39 |
+
<catalog_resource_eav_mysql4>
|
| 40 |
+
<rewrite>
|
| 41 |
+
<product_attribute_backend_tierprice>Elgentos_Tierpercentages_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice</product_attribute_backend_tierprice>
|
| 42 |
+
</rewrite>
|
| 43 |
+
</catalog_resource_eav_mysql4>
|
| 44 |
+
</models>
|
| 45 |
+
<resources>
|
| 46 |
+
<tierpercentages_setup>
|
| 47 |
+
<setup>
|
| 48 |
+
<module>Elgentos_Tierpercentages</module>
|
| 49 |
+
<class>Elgentos_Tierpercentages_Model_Mysql4_Setup</class>
|
| 50 |
+
</setup>
|
| 51 |
+
</tierpercentages_setup>
|
| 52 |
+
</resources>
|
| 53 |
+
|
| 54 |
+
<helpers>
|
| 55 |
+
<tierpercentages>
|
| 56 |
+
<class>Elgentos_Tierpercentages_Helper</class>
|
| 57 |
+
</tierpercentages>
|
| 58 |
+
</helpers>
|
| 59 |
+
</global>
|
| 60 |
+
</config>
|
app/code/local/Elgentos/Tierpercentages/sql/tierpercentages_setup/mysql4-install-0.1.0.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
$installer = $this;
|
| 3 |
+
$installer->startSetup();
|
| 4 |
+
$installer->run("ALTER TABLE {$this->getTable('catalog_product_entity_tier_price')} ADD percentage INT NOT NULL AFTER qty ; ");
|
| 5 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/template/tierpercentages/tier.phtml
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/afl-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 design
|
| 22 |
+
* @package default_default
|
| 23 |
+
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
/* @var $this Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier */
|
| 27 |
+
?>
|
| 28 |
+
<?php $_htmlId = $this->getElement()->getHtmlId() ?>
|
| 29 |
+
<?php $_htmlClass = $this->getElement()->getClass() ?>
|
| 30 |
+
<?php $_htmlName = $this->getElement()->getName() ?>
|
| 31 |
+
<?php $_readonly = $this->getElement()->getReadonly() ?>
|
| 32 |
+
<?php $_showWebsite = $this->isShowWebsiteColumn(); ?>
|
| 33 |
+
<?php $_editWebsite = $this->isAllowChangeWebsite(); ?>
|
| 34 |
+
<?php $_priceValueValidation = $this->getPriceValidation('validate-greater-than-zero'); ?>
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
<?php $_showWebsite = $this->isShowWebsiteColumn(); ?>
|
| 38 |
+
<?php $_showWebsite= $this->isMultiWebsites(); ?>
|
| 39 |
+
<tr>
|
| 40 |
+
<td class="label"><?php echo $this->getElement()->getLabel() ?></td>
|
| 41 |
+
<td colspan="10" class="grid tier">
|
| 42 |
+
<table cellspacing="0" class="data border" id="tiers_table">
|
| 43 |
+
<?php if ($_showWebsite): ?>
|
| 44 |
+
<col width="135" />
|
| 45 |
+
<?php endif; ?>
|
| 46 |
+
<col width="120" />
|
| 47 |
+
<col width="95" />
|
| 48 |
+
<col width="95" />
|
| 49 |
+
<col />
|
| 50 |
+
<col width="1" />
|
| 51 |
+
<thead>
|
| 52 |
+
<tr class="headings">
|
| 53 |
+
<th <?php if (!$_showWebsite): ?>style="display:none"<?php endif; ?>><?php echo Mage::helper('sales')->__('Website') ?></th>
|
| 54 |
+
<th><?php echo Mage::helper('catalog')->__('Customer Group') ?></th>
|
| 55 |
+
<th><?php echo Mage::helper('catalog')->__('Qty') ?></th>
|
| 56 |
+
<th><?php echo Mage::helper('catalog')->__('Percentage') ?></th>
|
| 57 |
+
<th><?php echo $this->getPriceColumnHeader(Mage::helper('catalog')->__('Price')) ?></th>
|
| 58 |
+
<th class="last"><?php echo Mage::helper('catalog')->__('Action') ?></th>
|
| 59 |
+
</tr>
|
| 60 |
+
</thead>
|
| 61 |
+
<tbody id="<?php echo $_htmlId ?>_container"></tbody>
|
| 62 |
+
<tfoot>
|
| 63 |
+
<tr>
|
| 64 |
+
<td <?php if (!$_showWebsite): ?>style="display:none"<?php endif; ?>></td>
|
| 65 |
+
<td colspan="5" class="a-right"><?php echo $this->getAddButtonHtml() ?></td>
|
| 66 |
+
</tr>
|
| 67 |
+
</tfoot>
|
| 68 |
+
</table>
|
| 69 |
+
|
| 70 |
+
<script type="text/javascript">
|
| 71 |
+
//<![CDATA[
|
| 72 |
+
var tierPriceRowTemplate = '<tr>'
|
| 73 |
+
+ '<td<?php if (!$_showWebsite): ?> style="display:none"<?php endif; ?>>'
|
| 74 |
+
+ '<select class="<?php echo $_htmlClass ?> required-entry" name="<?php echo $_htmlName ?>[{{index}}][website_id]" id="tier_price_row_{{index}}_website">'
|
| 75 |
+
<?php foreach ($this->getWebsites() as $_websiteId => $_info): ?>
|
| 76 |
+
+ '<option value="<?php echo $_websiteId ?>"><?php echo $this->jsQuoteEscape($this->htmlEscape($_info['name'])) ?><?php if (!empty($_info['currency'])): ?> [<?php echo $this->htmlEscape($_info['currency']) ?>]<?php endif; ?></option>'
|
| 77 |
+
<?php endforeach ?>
|
| 78 |
+
+ '</select></td>'
|
| 79 |
+
+ '<td><select class="<?php echo $_htmlClass ?> custgroup required-entry" name="<?php echo $_htmlName ?>[{{index}}][cust_group]" id="tier_price_row_{{index}}_cust_group">'
|
| 80 |
+
<?php foreach ($this->getCustomerGroups() as $_groupId=>$_groupName): ?>
|
| 81 |
+
+ '<option value="<?php echo $_groupId ?>"><?php echo $this->jsQuoteEscape($this->htmlEscape($_groupName)) ?></option>'
|
| 82 |
+
<?php endforeach ?>
|
| 83 |
+
+ '</select></td>'
|
| 84 |
+
+ '<td class="nobr"><input class="<?php echo $_htmlClass ?> qty required-entry validate-greater-than-zero" type="text" name="<?php echo $_htmlName ?>[{{index}}][price_qty]" value="{{qty}}" id="tier_price_row_{{index}}_qty" />'
|
| 85 |
+
+ ' <small class="nobr"><?php echo Mage::helper("catalog")->__("and above")?></small></td>'
|
| 86 |
+
+ '<td><input class="<?php echo $_htmlClass ?> percentage" type="text" name="<?php echo $_htmlName ?>[{{index}}][percentage]" value="{{percentage}}" id="tier_price_row_{{index}}_percentage" onblur="calculatePrice(this)" /></td>'
|
| 87 |
+
+ '<td><input class="<?php echo $_htmlClass ?> required-entry <?php echo $_priceValueValidation ?>" type="text" name="<?php echo $_htmlName ?>[{{index}}][price]" value="{{price}}" id="tier_price_row_{{index}}_price" /></td>'
|
| 88 |
+
+ '<td class="last"><input type="hidden" name="<?php echo $_htmlName ?>[{{index}}][delete]" class="delete" value="" id="tier_price_row_{{index}}_delete" />'
|
| 89 |
+
+ '<button title="<?php echo Mage::helper("catalog")->__("Delete Tier") ?>" type="button" class="scalable delete icon-btn delete-product-option" id="tier_price_row_{{index}}_delete_button" onclick="return tierPriceControl.deleteItem(event);">'
|
| 90 |
+
+ '<span><?php echo Mage::helper("catalog")->__("Delete") ?></span></button></td>'
|
| 91 |
+
+ '</tr>';
|
| 92 |
+
|
| 93 |
+
var tierPriceControl = {
|
| 94 |
+
template: new Template(tierPriceRowTemplate, new RegExp('(^|.|\\r|\\n)({{\\s*(\\w+)\\s*}})', "")),
|
| 95 |
+
itemsCount: 0,
|
| 96 |
+
addItem : function () {
|
| 97 |
+
<?php if ($_readonly): ?>
|
| 98 |
+
if (arguments.length < 4) {
|
| 99 |
+
return;
|
| 100 |
+
}
|
| 101 |
+
<?php endif; ?>
|
| 102 |
+
var data = {
|
| 103 |
+
website_id: '<?php echo $this->getDefaultWebsite() ?>',
|
| 104 |
+
group: '<?php echo $this->getDefaultCustomerGroup() ?>',
|
| 105 |
+
qty: '',
|
| 106 |
+
price: '',
|
| 107 |
+
readOnly: false,
|
| 108 |
+
index: this.itemsCount++
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
data.percentage = '';
|
| 112 |
+
if(arguments.length >= 4) {
|
| 113 |
+
data.website_id = arguments[0];
|
| 114 |
+
data.group = arguments[1];
|
| 115 |
+
data.qty = arguments[2];
|
| 116 |
+
data.price = arguments[3];
|
| 117 |
+
data.readOnly = arguments[4];
|
| 118 |
+
data.percentage = arguments[5];
|
| 119 |
+
}
|
| 120 |
+
if (arguments.length == 5) {
|
| 121 |
+
data.readOnly = arguments[4];
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Element.insert($('<?php echo $_htmlId ?>_container'), {
|
| 125 |
+
bottom : this.template.evaluate(data)
|
| 126 |
+
});
|
| 127 |
+
|
| 128 |
+
$('tier_price_row_' + data.index + '_cust_group').value = data.group;
|
| 129 |
+
$('tier_price_row_' + data.index + '_website').value = data.website_id;
|
| 130 |
+
$('tier_price_row_' + data.index + '_percentage').value = data.percentage;
|
| 131 |
+
|
| 132 |
+
<?php if ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()):?>
|
| 133 |
+
var wss = $('tier_price_row_' + data.index + '_website');
|
| 134 |
+
var txt = wss.options[wss.selectedIndex].text;
|
| 135 |
+
|
| 136 |
+
wss.insert({after:'<span class="website-name">' + txt + '</span>'});
|
| 137 |
+
wss.hide();
|
| 138 |
+
<?php endif;?>
|
| 139 |
+
|
| 140 |
+
if (data.readOnly == '1') {
|
| 141 |
+
['website', 'cust_group', 'qty', 'price', 'delete'].each(function(idx){
|
| 142 |
+
$('tier_price_row_'+data.index+'_'+idx).disabled = true;
|
| 143 |
+
});
|
| 144 |
+
$('tier_price_row_'+data.index+'_delete_button').hide();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
<?php if ($_readonly): ?>
|
| 148 |
+
$('<?php echo $_htmlId ?>_container').select('input', 'select').each(this.disableElement);
|
| 149 |
+
$('<?php echo $_htmlId ?>_container').up('table').select('button').each(this.disableElement);
|
| 150 |
+
<?php else: ?>
|
| 151 |
+
$('<?php echo $_htmlId ?>_container').select('input', 'select').each(function(el){ Event.observe(el, 'change', el.setHasChanges.bind(el)); });
|
| 152 |
+
<?php endif; ?>
|
| 153 |
+
},
|
| 154 |
+
disableElement: function(el) {
|
| 155 |
+
el.disabled = true;
|
| 156 |
+
el.addClassName('disabled');
|
| 157 |
+
},
|
| 158 |
+
deleteItem: function(event) {
|
| 159 |
+
var tr = Event.findElement(event, 'tr');
|
| 160 |
+
if (tr) {
|
| 161 |
+
Element.select(tr, '.delete').each(function(elem){elem.value='1'});
|
| 162 |
+
Element.select(tr, ['input', 'select']).each(function(elem){elem.hide()});
|
| 163 |
+
Element.hide(tr);
|
| 164 |
+
Element.addClassName(tr, 'no-display template');
|
| 165 |
+
}
|
| 166 |
+
return false;
|
| 167 |
+
}
|
| 168 |
+
};
|
| 169 |
+
<?php foreach ($this->getValues() as $_item): ?>
|
| 170 |
+
tierPriceControl.addItem('<?php echo $_item['website_id'] ?>', '<?php echo $_item['cust_group'] ?>', '<?php echo $_item['price_qty']*1 ?>', '<?php echo sprintf('%.2f', $_item['price']) ?>', <?php echo (int)!empty($_item['readonly'])?>, '<?php echo (isset($_item['percentage']) ? $_item['percentage'] : "0"); ?>');
|
| 171 |
+
<?php endforeach; ?>
|
| 172 |
+
<?php if ($_readonly): ?>
|
| 173 |
+
$('<?php echo $_htmlId ?>_container').up('table').select('button')
|
| 174 |
+
.each(tierPriceControl.disableElement);
|
| 175 |
+
<?php endif; ?>
|
| 176 |
+
//]]>
|
| 177 |
+
</script>
|
| 178 |
+
</td></tr>
|
app/etc/modules/Elgentos_Tierpercentages.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Elgentos_Tierpercentages>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>local</codePool>
|
| 7 |
+
</Elgentos_Tierpercentages>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
js/elgentos/tierpercentages.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function calculatePrice(el) {
|
| 2 |
+
id = el.id;
|
| 3 |
+
normal_price = $('price').value;
|
| 4 |
+
special_price = $('special_price').value;
|
| 5 |
+
if(special_price.length===0) { price = normal_price; priceType="normal price"; } else { price = special_price; priceType = "special price"; }
|
| 6 |
+
percentage = el.value;
|
| 7 |
+
priceInput = id.replace('percentage','price');
|
| 8 |
+
newPrice = price*(percentage/100);
|
| 9 |
+
currPrice = $(priceInput).value;
|
| 10 |
+
if(newPrice!=currPrice && confirm("Do you want to update this tier price from "+currPrice+" to "+newPrice+" based on the "+priceType+"?")) {
|
| 11 |
+
$(priceInput).value = newPrice;
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
document.observe("dom:loaded", function() {
|
| 16 |
+
normal_price = $('price').value;
|
| 17 |
+
special_price = $('special_price').value;
|
| 18 |
+
|
| 19 |
+
$('price').observe('blur',function(event) {
|
| 20 |
+
newPrice = $('price').value;
|
| 21 |
+
if(normal_price!=newPrice && confirm("Do you want to update the tier prices?")) {
|
| 22 |
+
$$('input.percentage').each(function (el) {
|
| 23 |
+
id = el.id;
|
| 24 |
+
price = $('price').value;
|
| 25 |
+
percentage = el.value;
|
| 26 |
+
priceInput = id.replace('percentage','price');
|
| 27 |
+
$(priceInput).value = price*(percentage/100);
|
| 28 |
+
});
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
$('special_price').observe('blur',function(event) {
|
| 32 |
+
newPrice = $('special_price').value;
|
| 33 |
+
if(newPrice.length!==0 && special_price!=newPrice && confirm("Do you want to update the tier prices to adhere to the special price?")) {
|
| 34 |
+
$$('input.percentage').each(function (el) {
|
| 35 |
+
id = el.id;
|
| 36 |
+
price = $('special_price').value;
|
| 37 |
+
percentage = el.value;
|
| 38 |
+
priceInput = id.replace('percentage','price');
|
| 39 |
+
$(priceInput).value = price*(percentage/100);
|
| 40 |
+
});
|
| 41 |
+
}
|
| 42 |
+
});
|
| 43 |
+
});
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Elgentos_Tierpercentages</name>
|
| 4 |
+
<version>0.1.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>GPL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>This module allows you to fill out percentages in the Tier pricing part under Prices. It will automatically calculate the eventual price for you.</summary>
|
| 10 |
+
<description>This module allows you to fill out percentages in the Tier pricing part under Prices. It will automatically calculate the eventual price for you.</description>
|
| 11 |
+
<notes>First release</notes>
|
| 12 |
+
<authors><author><name>Peter Jaap Blaakmeer</name><user>elgentos</user><email>peterjaap@elgentos.nl</email></author></authors>
|
| 13 |
+
<date>2012-04-11</date>
|
| 14 |
+
<time>14:12:05</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Elgentos"><dir name="Tierpercentages"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><dir name="Price"><file name="Tier.php" hash="f93380fe4883013f84a610eee7a63538"/></dir></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="a7245b57ce0456eac30d2bb71338e684"/></dir><dir name="Model"><dir name="Mysql4"><file name="Setup.php" hash="79201aa741f6c1e1674de3e5abb00dbf"/></dir><dir name="Product"><dir name="Attribute"><dir name="Backend"><file name="Tierprice.php" hash="bd1595da177090282fca3cbe3cdfabcf"/></dir></dir></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><dir name="Product"><dir name="Attribute"><dir name="Backend"><file name="Tierprice.php" hash="00568c971b7c68447ca091f45dd6893e"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="c49e5fa08c6709295b82050d97fa1b9c"/></dir><dir name="sql"><dir name="tierpercentages_setup"><file name="mysql4-install-0.1.0.php" hash="3068e027808e2b3c3401b63b563bf947"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Elgentos_Tierpercentages.xml" hash="4804bbc80a133fc963630ecd5323a586"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="tierpercentages"><file name="tier.phtml" hash="831ac0aa1667ca76c404e04d7657f333"/></dir><dir name="layout"><file name="tierpercentages.xml" hash=""/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="elgentos"><file name="tierpercentages.js" hash="a1216b62c86d77a902fa1c1a9e4dc35a"/></dir></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>4.0.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
+
</package>
|
