magento可以节省您的购物车总额

时间:2012-01-27 18:24:04

标签: php magento e-commerce

我一直在谷歌上搜索疯狂..我想要一个简单的事情。从购物车中所有产品的特殊/试用/调整总价格中获取所有产品的总价格与正常价格的差异。

IE:如果购物车中有2件商品具有正常价格属性,例如

1 @ $5
2 @ $10
--------------------------
total = $15 Savings = $0

但是我在#2上特价,所以购物车将是

1 @ $5
2 @ $5
--------------------------
total = $10 Savings = $5

现在我知道我可以使用

$this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); 

要获得总计,但我不是100%,这不是没有运输..但这将是应用的特殊价格。我需要总的正常成本,然后我可以从那里做简单的数学。

我想要做的是将它们放在标题和侧栏中的数字中..想法?

1 个答案:

答案 0 :(得分:0)

在产品视图页面

<?php 
   $_product = $this->getProduct(); ?>  

   if ($_product->getTypeId() == 'bundle'){
      list($_minimalPrice, $_maximalPrice) = $_product->getPriceModel()->getPrices($_product);
      $this->_price = $_minimalPrice;
      $this->_specialPrice = $_minimalPrice;
      if (!is_null($_product->getData('special_price')) && ($_product->getData('special_price') < 100)){  
         $this->_regularPrice = ($this->_specialPrice / $_product->getData('special_price')) * 100;  
      } else {
         $this->_regularPrice = $this->_specialPrice;
      }
    } else {
       $this->_price = 0;
       $this->_regularPrice = $_product->getPrice();
       $this->_specialPrice = $_product->getFinalPrice();
    }
    if ( $this->_specialPrice != $this->_regularPrice )
    {
       if ($this->_regularPrice > 0)
       {
          $this->_discountAmount = round( ( 1 - $this->_specialPrice / $this->_regularPrice ) * 100 );
          $this->_saveAmount = $this->_regularPrice - $this->_specialPrice;
       }
     }

    if ($this->_regularPrice)
    {
        $this->_regularPrice = strip_tags( Mage::app()->getStore()->convertPrice( $this->_regularPrice, true ) );
    }
    if ($this->_specialPrice)
    {
        $this->_specialPrice = strip_tags( Mage::app()->getStore()->convertPrice( $this->_specialPrice, true ) );
    }
    if ($this->_saveAmount)
    {
        $this->_saveAmount   = strip_tags( Mage::app()->getStore()->convertPrice( $this->_saveAmount, true )   );
    }
    if ($this->_discountAmount)
    {
        $this->_discountAmount = $this->_discountAmount . '%';
    }

所以,有_saveAmount_discountAmount,在你的模板中使用,但我没有测试它,在生产网站上要小心。

相关问题