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?

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/>';
} 
  • Outstanding. And, in addition, I needed to compare: code $_productB->getFinalPrice() != $_productA->getPrice() Thanks a million. – Sean McGown Mar 15 '17 at 3:09

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.