Magento 1x 全局价格规则控制 以及快速定位 文件及JS

7天成为Magento系统架构师,现在开始学习Magento全栈开发!

《Magento2.X企业级开发实战》


自定义 购物车规则 观测者模式

XML 写法

   
        Aps_Weicot_Block<.....>Aps_Weicot_Model_ObserverproductsPriceUpdate<.....>

购物车页面价格控制

getQuoteItem();
        // Ensure we have the parent item, if it has one
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        // Load the custom price


       // var_dump($item->getProduct()->getCategoryIds());
       // die('here');

        Mage::log($item->getProduct()->getCategoryIds(),null,"catalog.log");
        if(
            $item->getProduct()->getCategoryIds()[0]_getPriceByItem($item);
            // Set the custom price
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            // Enable super mode on the product.
            $item->getProduct()->setIsSuperMode(true);
        }
    }

    protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
    {
        $price="99";

        //use $item to determine your custom price.

        return $price;
    }

}

产品页面价格规则 调用的 JSON 数据

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/28 0028
 * appdesignfrontendrwddefaulttemplatecatalogproductview.phtml
 */


/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
helper('catalog/output'); ?>
getProduct(); ?>

通过全局搜索 function getJsonConfig() 可得调用方法

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/28 0028
 * appcodecoreMageCatalogBlockProductView.php
 */

public function getJsonConfig()
    {
        $config = array();
        if (!$this->hasOptions()) {
            return Mage::helper('core')->jsonEncode($config);
        }

        $_request = Mage::getSingleton('tax/calculation')->getDefaultRateRequest();
        /* @var $product Mage_Catalog_Model_Product */
        $product = $this->getProduct();
        $_request->setProductClassId($product->getTaxClassId());
        $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);

        $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
        $_request->setProductClassId($product->getTaxClassId());
        $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);

        $_regularPrice = $product->getPrice();
        $_finalPrice = $product->getFinalPrice();
        if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
            $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true,
                null, null, null, null, null, false);
            $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, false,
                null, null, null, null, null, false);
        } else {
            $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true);
            $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice);
        }
        $_tierPrices = array();
        $_tierPricesInclTax = array();
        foreach ($product->getTierPrice() as $tierPrice) {
            $_tierPrices[] = Mage::helper('core')->currency(
                Mage::helper('tax')->getPrice($product, (float)$tierPrice['website_price'], false) - $_priceExclTax
                    , false, false);
            $_tierPricesInclTax[] = Mage::helper('core')->currency(
                Mage::helper('tax')->getPrice($product, (float)$tierPrice['website_price'], true) - $_priceInclTax
                    , false, false);
        }
        $config = array(
            'productId'           => $product->getId(),
            'priceFormat'         => Mage::app()->getLocale()->getJsPriceFormat(),
            'includeTax'          => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
            'showIncludeTax'      => Mage::helper('tax')->displayPriceIncludingTax(),
            'showBothPrices'      => Mage::helper('tax')->displayBothPrices(),
            'productPrice'        => Mage::helper('core')->currency($_finalPrice, false, false),
            'productOldPrice'     => Mage::helper('core')->currency($_regularPrice, false, false),
            'priceInclTax'        => Mage::helper('core')->currency($_priceInclTax, false, false),
            'priceExclTax'        => Mage::helper('core')->currency($_priceExclTax, false, false),
            /**
             * @var skipCalculate
             * @deprecated after 1.5.1.0
             */
            'skipCalculate'       => ($_priceExclTax != $_priceInclTax ? 0 : 1),
            'defaultTax'          => $defaultTax,
            'currentTax'          => $currentTax,
            'idSuffix'            => '_clone',
            'oldPlusDisposition'  => 0,
            'plusDisposition'     => 0,
            'plusDispositionTax'  => 0,
            'oldMinusDisposition' => 0,
            'minusDisposition'    => 0,
            'tierPrices'          => $_tierPrices,
            'tierPricesInclTax'   => $_tierPricesInclTax,
        );

        $responseObject = new Varien_Object();
        Mage::dispatchEvent('catalog_product_view_config', array('response_object' => $responseObject));
        if (is_array($responseObject->getAdditionalOptions())) {
            foreach ($responseObject->getAdditionalOptions() as $option => $value) {
                $config[$option] = $value;
            }
        }

        return Mage::helper('core')->jsonEncode($config);
    }

通过 Mage::helper(‘core’)->jsonEncode($config) 可获的 生成数据

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/28 0028
 * 无特价
 */
var optionsPrice = new Product.OptionsPrice({
    "productId": "270",
    "priceFormat": {
        "pattern": "uffe5u00a0%s",
        "precision": 2,
        "requiredPrecision": 2,
        "decimalSymbol": ".",
        "groupSymbol": ",",
        "groupLength": 3,
        "integerRequired": 1
    },
    "includeTax": "false",
    "showIncludeTax": false,
    "showBothPrices": false,
    "productPrice": 18.19,
    "productOldPrice": 18.19,
    "priceInclTax": 18.19,
    "priceExclTax": 18.19,
    "skipCalculate": 1,
    "defaultTax": 0,
    "currentTax": 0,
    "idSuffix": "_clone",
    "oldPlusDisposition": 0,
    "plusDisposition": 0,
    "plusDispositionTax": 0,
    "oldMinusDisposition": 0,
    "minusDisposition": 0,
    "tierPrices": [],
    "tierPricesInclTax": []
});

//有特价
var optionsPrice = new Product.OptionsPrice({
    "productId": "2009",
    "priceFormat": {
        "pattern": "uffe5u00a0%s",
        "precision": 2,
        "requiredPrecision": 2,
        "decimalSymbol": ".",
        "groupSymbol": ",",
        "groupLength": 3,
        "integerRequired": 1
    },
    "includeTax": "false",
    "showIncludeTax": false,
    "showBothPrices": false,
    "productPrice": 24.7,
    "productOldPrice": 29.7,
    "priceInclTax": 24.7,
    "priceExclTax": 24.7,
    "skipCalculate": 1,
    "defaultTax": 0,
    "currentTax": 0,
    "idSuffix": "_clone",
    "oldPlusDisposition": 0,
    "plusDisposition": 0,
    "plusDispositionTax": 0,
    "oldMinusDisposition": 0,
    "minusDisposition": 0,
    "tierPrices": [],
    "tierPricesInclTax": []
});

通过 Product.OptionsPrice 可追踪到 调用 JS 函数的PHTM

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/28 0028
 * appdesignfrontendbasedefaulttemplatecatalogproductviewoptions.phtml
 */

         if(element.type == 'select-multiple' && ('options' in element)) {
                        $A(element.options).each(function(selectOption) {
                            if (('selected' in selectOption) && typeof(configOptions[selectOption.value]) != 'undefined') {
                                if (selectOption.selected) {
                                    curConfig = configOptions[selectOption.value];
                                } else {
                                    curConfig = {price: 0};
                                }
                                optionsPrice.addCustomPrices(optionId + '-' + selectOption.value, curConfig);
                                optionsPrice.reload();
                            }
                        });
                    } else {
                        optionsPrice.addCustomPrices(element.id || optionId, curConfig);
                        optionsPrice.reload();
                    }

通过 搜索 addCustomPrices optionsPrice.reload() 追踪到调用的JS 库

//有特价 自动修改 js 代码
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/28 0028
 * jsvarienproduct.js
 */ 
         if (price > 0 || this.displayZeroPrice) {
                    formattedPrice = this.formatPrice(price);
                } else {
                    formattedPrice = '';
                }

                if ($(pair.value).select('.price')[0]) {
                    $(pair.value).select('.price')[0].innerHTML = formattedPrice;
                    if ($(pair.value+this.duplicateIdSuffix) && $(pair.value+this.duplicateIdSuffix).select('.price')[0]) {
                        $(pair.value+this.duplicateIdSuffix).select('.price')[0].innerHTML = formattedPrice;
                    }
                } else {
                    $(pair.value).innerHTML = formattedPrice+"W";//测试 单位万 后缀
                    if ($(pair.value+this.duplicateIdSuffix)) {
                        $(pair.value+this.duplicateIdSuffix).innerHTML = formattedPrice+"W"; //测试 单位万 后缀
                    }
                }

转载请注明:(●–●) Hello.My Weicot » Magento 1x 全局价格规则控制 以及快速定位 文件及JS

文章来源于互联网:Magento 1x 全局价格规则控制 以及快速定位 文件及JS

如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。