1

I am trying to divide product price by pack to display an each price.

My PHP knowledge is very poor, so any help/direction would be a massive help.

Each product/price is part of a pack, I will be selling by the pack price but I would also like to display an each price.

So far I have the following:

<?php $_packAmount = $_product->getPack(); ?>
                <?php $_productPrice = $_product->getPrice(); ?>
                <?php $_each = $_productPrice / $_packAmount; ?>
                <?php echo (round($_each,2)); ?>

This appears to work ok, but if the product is using a special price it ignores the special price and uses the main product price.

I need to be able to divide by the product price it is using at the time (regular or special price) also needs to display in the correct currency.

I have also setup an additional attribute in back end called "mkt_price" I would like this to override the each price if a value exists.

Thanks in advance (Magento version 1.9.2)

1

You can try and use:

product->getFinalPrice()

This should get the final price.

foreach ($collection as $product){
    if($product->getFinalPrice() < $product->getPrice()){
       // Your code here

    }
}
  • Hi Steven, this does not seem to work, are you able to paste full code including my own so I can try? Sorry to be a pain. – Billy Parker Feb 19 '16 at 17:09
  • Sorry can I confirm which template .phtml file you are currently editing? – Steven Church Feb 22 '16 at 9:43

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.