0

I'm trying to change the class name in the HTML output from "price". I was hoping to find it in the code block below.

The following code (frontend/default/theme/template/page/html/cart.phtml):

<div class="shopping_cart_b">
    <a href="#" class="open">
        <?php echo $this->__('Shopping Cart:'); ?>
        <?php echo $_cartQty; ?> <span><?php echo $this->__('Item(s) - '); ?></span>

        <?php if ($this->canApplyMsrp()): ?>
            <?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?>
        <?php else: ?>
            <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
            <?php if ($_subtotalInclTax = $this->getSubtotalInclTax()): ?>
                (<?php echo Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?php echo Mage::helper('tax')->getIncExcText(true) ?>)
            <?php endif; ?>
        <?php endif; ?>

    </a>
</div>

Produces the following output (in Header):

<div class="shopping_cart_b">
    <a href="#" class="open">
        Shopping Cart: 
            <span>Item(s) - </span>
            <span class="price">£0.00</span>                                     
    </a>
</div>

Block Name Hint:

Mage_Checkout_Block_Cart_Sidebar

I've determined that <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?> is responsible for calling <span class="price">£0.00</span>, but I've no idea where to find the actual file to change the CSS class.

I've used grep to try and find the file, but there are too many results. Any help appreciated.

  • Enable path hints – PЯINCƏ Apr 3 '18 at 22:19
  • That just leads me back to the file containing the block of code I have already provided. – Craig Apr 3 '18 at 22:21
  • If you have the block name you should find it, please add exactly the page where you want to add your class cart, product list etc... i Will look that tomorrow – PЯINCƏ Apr 3 '18 at 22:32
1

What you are looking for is something that you won't find in a phtml file. The magento helper function has a second parameter that is by default, set true. The parameter, I believe is whether to include the container or not. The container, if my memory is correct, is where html is being included and perhaps the class name is within the code. I strongly suggest NOT updating the code, but rather apply a second parameter of false and see what sort of output you can then work with. If what I say is correct, it should be simply the price. Therefore, try this as a solution:

<span class="price price-customclass"><?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal(), false) ?></span>

I strongly suggest to append your new class name, instead of replacing the original. Keeping the original class name price would be helpful to ensure that anything referencing or depending on that class is not affected.

CORRECTION

The code above is incorrectly assumed, but ultimately correct if you trace the function calls. The call I have in the code snippet actually doesn't allow for a second parameter. Tracing call hierarchy reveals that you may substitute that code with:

Mage::getSingleton('checkout/session')->getQuote()->getStore()->formatPrice($price, false);

UPDATE

As I had suggested above, the class name is, in fact, applied by code not found within a template file. The code below was found within: magento/app/code/core/Mage/Directory/Model/Currency.php

   if ($includeContainer) {
            return '<span class="price">' . ($addBrackets ? '[' : '') . $this->formatTxt($price, $options) .
                ($addBrackets ? ']' : '') . '</span>';
        }

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.