简体   繁体   English

magento节省您的购物车总额

[英]magento get savings total of your cart

I have been googling like mad here.. I want a simple thing. 我一直在疯狂地谷歌搜索..我想要一个简单的东西。 Get the difference of the total price of all the products at the normal price, from the total special/tried/adjusted price of all the products in a cart. 从购物车中所有产品的特殊/试用/调整后的总价格中,以正常价格获得所有产品的总价格之差。

IE: if I had 2 items in the cart that have the normal price attribute like IE:如果购物车中有2个商品具有正常的价格属性,例如

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

but I then I make a special price on #2 so the cart would be 但是我随后在#2上做出了特价,因此购物车会

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

Now I know I can use 现在我知道我可以使用

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

To get the grand total, but I'm not 100% that is not without the shipping.. but that would be with the special price applied. 要获得总计,但我不是100%,这不是没有运费的..但这将应用特殊的价格。 I would need the total normal cost too then I can do the simple math from there. 我也需要正常的总费用,然后我可以从那里进行简单的数学计算。

What I'm wanting to do is put these to numbers in the header and the side bar.. Ideas? 我想做的就是将这些放在标题和侧栏中的数字中。

on product view page 在产品查看页面上

<?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 . '%';
    }

so, there is _saveAmount and _discountAmount , use in your template but I didn't test it, be careful on production site. 因此,在模板中使用了_saveAmount_discountAmount ,但是我没有对其进行测试,请在生产站点上小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM