0

I want to add this text on certain product pages:

Free gift with purchase.

Then I want to add that same text to the cart.

Only for certain products.

How can I do this?

1

You have to create some block and display it product page, cart page then you display that text just in some conditions !

Product page:

1) app/design/frontend/{your_package}/{your_theme}/template/text-product/mytext.phtml

<?php $productId = Mage::registry('current_product')->getId(); ?>

<?php if ($productId == '10') : ?> // here the product id that you want to display this text
    <?php echo $this->__('My text for a product id 10'); ?>
   //or
   <div class="my-text">...</div>
<?php endif; ?>

2) app/design/frontend/{your_package}/{your_theme}/template/catalog/product/view.phtml

<?php echo $this->getBlockHtml('mycustom.product.text'); ?>

3) app/design/frontend/{your_package}/{your_theme}/layout/local.xml

//add the bellow code before </default>

<catalog_product_view>
    <reference name="root">
        <block type="core/template" name="mycustom.product.text" template="text-product/mytext.phtml" />
    </reference>
</catalog_product_view>

Cart page:

1) app/design/frontend/{your_package}/{your_theme}/template/text-product/mytext-cart.phtml

<?php
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$productIds = array();
foreach($quote->getAllItems() as $item) {
    $productIds[] = $item->getProductId();  
}
?>
//if among all the products in cart you find product id: 10, display this text
<?php if(in_array('10', $productIds)): ?> 
    <?php echo $this->__('My text for a product id 10'); ?>
   //or
   <div class="my-text">...</div>
<?php endif; ?>

2) app/design/frontend/{your_package}/{your_theme}/template/checkout/cart.phtml

<?php echo $this->getBlockHtml('mycustom.cart.text'); ?>

3) app/design/frontend/{your_package}/{your_theme}/layout/local.xml

//add the bellow code before </default>

<checkout_cart_index>
    <reference name="root">
        <block type="core/template" name="mycustom.cart.text" template="text-product/mytext-cart.phtml" />
    </reference>
</checkout_cart_index>

Enjoy

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.