2013-06-27 32 views
0

我在Magento中使用onestepcheckout。我增加了一些額外的固定費率,我使用了其中兩個。我希望能夠僅顯示取決於購物車小計的統一費率之一。如果陳述只顯示數組中的一個值

我已經將小計變成了一個變量,但代碼有一個foreach,通過每種運輸方法可用,所以我需要一種方法來說,如果$total超過500只顯示第二種運輸方法,如果總數低於500只顯示第一種運輸方式。

<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?> 
       <?php foreach ($_shippingRateGroups as $code => $_rates): ?> 
          <dd><?php echo $this->getCarrierName($code) ?></dd> 
         <?php foreach ($_rates as $_rate): ?> 
          <dt style="margin-bottom: 5px;"> 

           <?php if ($_rate->getErrorMessage()): ?> 
           <ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul> 
           <?php else: ?> 
            <input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> /> 
            <label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?> 
            <strong> 
            <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?> 
            <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?> 

            <?php echo $_excl; ?> 
            <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?> 
             (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>) 
            <?php endif; ?> 
            </strong> 
            </label> 
           <?php endif ?> 
          </dt> 
         <?php endforeach; ?> 
       <?php endforeach; ?> 
+0

什麼部分,具體是你有麻煩嗎?它看起來像你已經知道如何使用'if'語句。 – sgroves

+0

@sgroves我需要一種方法來獲得兩個不同的速率'flatrate'和'flatrate2'到if語句中 – Matt

+0

在這段代碼中,沒有任何地方顯示flatrate或flatrate2任何地方,他們的方法嗎?或變量?或者是什麼? – KyleK

回答

0

只是做...

//first method here by default 
if($total>500){ 
//second method here 
} 

東西告訴我,你已經知道如何做到這一點,雖然

我認不出,什麼第一和第二種方法是在你的代碼,否則我會發布更完整的代碼

+0

我已經嘗試過,但不會更新ajax部分。 – Matt

+0

什麼ajax部分?你沒有顯示任何ajax部分 – KyleK

+0

它使用onestepcheckout ajax部分是分開的。第一種方法是'flatrate'第二種方法是'flatrate2' – Matt