1

I've put together a blurb to show logged out customers what they can pay if they create an account and log in.

Some of our products don't have a lower price so I want to omit the blurb for products that don't have a lower price when logged in. I tried a conditional to look for conditions where the product prices were different between the two states.

<!-- Add price discount code here -->
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
<?php $_productA = $this->getProduct();
$_productB = Mage::getModel('catalog/product')->load($_productA->getId());  
$_productB->setCustomerGroupId(4);
if ($_productB != $_productA ) {
echo '<p>If you were logged in,<br />your price would be: $'.round($_productB->getFinalPrice(),2).'<br/>';
} ?>
<?php endif; ?>
<!-- End price discount code here -->

But it shows the code on every product. What am I missing?

1 Answer 1

0

You are just checking if the two product objects are the same. In order to know about the price you would need to call $product->getPrice()

if ($_productB->getPrice() != $_productA->getPrice() ) {
    echo '<p>If you were logged in,<br />your price would be:  $'.round($_productB->getFinalPrice(),2).'<br/>';
} 
1
  • Outstanding. And, in addition, I needed to compare: code $_productB->getFinalPrice() != $_productA->getPrice() Thanks a million. Commented Mar 15, 2017 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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