0

please visit this : link

search for Rs 10 using ctrl + F

here i am displaying attribute value [i.e 10 ] ,

1) If we entered value as "0" in textfield than we displaying "free delivery" as here

If there is no value entered in textfield [attribute value], than i want to display "50" = > Selling price + Rs 50 Delivery. but now its displaying like this : link

attribute code : "mp_local_shipping_charge"

Price.phtml

<span class="price-label"><?php echo $_specialPriceStoreLabel ?></span>
<span class="price" id="product-price-<?php echo $_id ?>
<?php echo $this->getIdSuffix() ?>"
<?php if($helperSettings->isShowOfferPrice($_product)):?> itemprop="lowPrice"<?php endif;?>>
<?php echo $_coreHelper->formatPrice($_finalPrice, false) ?>
<?php $deliveryPrice = $_product->getData("mp_local_shipping_charge");
if($deliveryPrice == 0){ ?>
<p class="sell_price"><?php echo "Selling Price (Free Delivery )"; ?> </p>
<?php }elseif(empty($deliveryPrice)) { ?>
<p class="sell_price"><?php echo "Selling Price + Rs 50 Delivery "; ?> </p>
<?php }else { ?>
<p class="sell_price"><?php echo "Selling Price"; ?>
<?php echo "+ Rs " . $_product->getData("mp_local_shipping_charge") . " Delivery "; ?>
<?php } ?>
7
  • What is type and default value for mp_local_shipping_charge attribute? Feb 13 '16 at 12:04
  • its textfield type attribute Feb 13 '16 at 13:04
  • pls let me know if you need other information Feb 13 '16 at 13:16
  • Try to echo var_dump($deliveryPrice); before if{}else{} condition, and see what will be the result. Feb 13 '16 at 13:17
  • its displying like this : string(2) "10 infront of RS Feb 13 '16 at 13:32
1

the first thing i had to do was a little cleanup, so here is the readable version of your above code:

<span class="price-label"><?php echo $_specialPriceStoreLabel ?></span>
<span class="price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>"<?php if($helperSettings->isShowOfferPrice($_product)):?> itemprop="lowPrice"<?php endif;?>>
    <?php echo $_coreHelper->formatPrice($_finalPrice, false) ?>
    <?php $deliveryPrice = $_product->getData("mp_local_shipping_charge") ?>
    <?php if($deliveryPrice == 0): ?>
        <p class="sell_price"><?php echo "Selling Price (Free Delivery )"; ?> </p>
    <?php elseif(empty($deliveryPrice)): ?>
        <p class="sell_price"><?php echo "Selling Price + Rs 50 Delivery "; ?> </p>
    <?php else: ?>
        <p class="sell_price"><?php echo "Selling Price"; ?>
        <?php echo "+ Rs " . $_product->getData("mp_local_shipping_charge") . " Delivery "; ?>
    <?php endif; ?>

The problem is, that the first if is using == operator, which does not check for the type. So in php, 0 == "" is true.

To solve this, you can use the === operator and instead of checking for 0 (which is a number) you check for "0" as a string or whatever is exactly in the attribute (you can get the type and value with var_dump($var) )

In Short, this should do it:

<span class="price-label"><?php echo $_specialPriceStoreLabel ?></span>
<span class="price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>"<?php if($helperSettings->isShowOfferPrice($_product)):?> itemprop="lowPrice"<?php endif;?>>
    <?php echo $_coreHelper->formatPrice($_finalPrice, false) ?>
    <?php $deliveryPrice = $_product->getData("mp_local_shipping_charge") ?>
    <?php if($deliveryPrice === "0"): ?>
        <p class="sell_price"><?php echo "Selling Price (Free Delivery )"; ?> </p>
    <?php elseif(empty($deliveryPrice)): ?>
        <p class="sell_price"><?php echo "Selling Price + Rs 50 Delivery "; ?> </p>
    <?php else: ?>
        <p class="sell_price"><?php echo "Selling Price"; ?>
        <?php echo "+ Rs " . $_product->getData("mp_local_shipping_charge") . " Delivery "; ?>
    <?php endif; ?>
1
  • Thanks a lot boss : ) When you gave answer, for sure it will work... Feb 13 '16 at 15:47
1

Why don't you just make default value equal 50. So then if any other values is enter, in this case 0, it will be changed.

From my personnel experience it's always better to have some value to be calculated off and it's easier to filter in the backend.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.