2017-07-25 81 views
2

我想显示客户保存的实际价格而不是百分比值,但是我不是PHP专家,并且对如何解决此问题存在困难。Magento 1.9 tierclricing calculation

目前,我的商店页面上显示了分层价格显示,如下所示。

<!-- Display product tier price --> 
<?php 
    $_product = $this->getProduct(); 
    $_tierPrices = $this->getTierPrices(); 
    if (count($_tierPrices) > 0): 
     $_data = array(); 
     $_prevQty = 0; 
     $_counter = 0; 
     $_tierPrices = array_reverse($_tierPrices); 
     foreach ($_tierPrices as $_index => $_price){ 
      $_counter++; 
       $label = $_price['price_qty']; 
       $_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price'],'save'=>$_price['savePercent']); 
       $_prevQty = $_price['price_qty']; 
     } 
     $_data = array_reverse($_data); ?> 
     <table class="price-table" id="price-tier"> 
      <tbody> 
       <tr> 
        <th>Antal</th> 
        <th>Pris</th> 
        <th>Spar</th> 
       </tr> 
      <?php foreach ($_data as $_row): ?> 
       <tr> 
        <td><?php echo $_row['label']; ?></td> 
        <td><?php echo $_row['price']; ?></td> 
        <td><?php echo $_row['save']."%"; ?></td> 
       </tr> 
      <?php endforeach; ?> 
      </tbody> 
     </table> 
<?php 
    endif; ?> 

我希望有人在那里可以指出我在正确的方向。

回答

0

,同时通过分级定价的循环,你可以工作,通过$_product->getFinalPrice() 扣除$_price['price']看我下面的修改foreach循环,节约了ammount的,你可以贴在你的现有代码

foreach ($_tierPrices as $_index => $_price){ 
       $_counter++; 
        $label = $_price['price_qty']; 
        $_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price'],'save'=>$_product->getFinalPrice()-$_price['price']); 
        $_prevQty = $_price['price_qty']; 
      } 

要延长此,$this->getProduct()返回Mage_Catalog_Model_Product的实例,我们可以使用getFinalPrice()来获得产品的最终价格。

$this->getTierPrices()返回分层价格数据的多维阵列,其中包含稍微不同的数据比如果直接从产品对象获取的分层定价,下面是阵列

array(3) { 
    [0]=> 
    array(10) { 
    ["price_id"]=> 
    string(1) "1" 
    ["website_id"]=> 
    string(1) "1" 
    ["all_groups"]=> 
    string(1) "0" 
    ["cust_group"]=> 
    string(1) "0" 
    ["price"]=> 
    float(341.39) 
    ["price_qty"]=> 
    float(5) 
    ["website_price"]=> 
    float(341.39) 
    ["formated_price"]=> 
    string(47) "£341.39" 
    ["savePercent"]=> 
    float(3) 
    ["formated_price_incl_tax"]=> 
    string(47) "£341.39" 
    } 
    [1]=> 
    array(10){ 
    ... 
    } 
    ... 
} 

内的一个项目的例子全码:

<!-- Display product tier price --> 
<?php 
    $_product = $this->getProduct(); 
    $_tierPrices = $this->getTierPrices(); 
    if (count($_tierPrices) > 0): 
     $_data = array(); 
     $_prevQty = 0; 
     $_counter = 0; 
     $_tierPrices = array_reverse($_tierPrices); 
     foreach ($_tierPrices as $_index => $_price){ 
      $_counter++; 
       $label = $_price['price_qty']; 
       $_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price'],'save'=>$_product->getFinalPrice()-$_price['price']); 
       $_prevQty = $_price['price_qty']; 
     } 
     $_data = array_reverse($_data); ?> 
     <table class="price-table" id="price-tier"> 
      <tbody> 
       <tr> 
        <th>Antal</th> 
        <th>Pris</th> 
        <th>Spar</th> 
       </tr> 
      <?php foreach ($_data as $_row): ?> 
       <tr> 
        <td><?php echo $_row['label']; ?></td> 
        <td><?php echo $_row['price']; ?></td> 
        <td><?php echo $_row['save']; ?></td> 
       </tr> 
      <?php endforeach; ?> 
      </tbody> 
     </table> 
<?php 
    endif; ?> 
+0

伊夫尝试了上面的代码,但我仍然得到的百分比值。这可能是因为我在表代中回应了错误的值? – MrB

+0

我会把你现在需要的完整的代码片段发给你 –

+0

请看我更新的答案,我还需要在echo $ _row ['save']后删除'%'字符串;基本上我们所做的是将$ _row ['save']设置为原始价格减去分层价格,并删除了此值后出现的百分比符号。 –