I have had an affiliate extension that allows my store to accept affiliate feeds.

I wish to change the Add to Bag text on the category page to open a window that then redirects to the products on the partnered site.

The code for the category page is: -

<?php if($_product->isSaleable()): ?>
                        <div class="add-to-bag grid12-6 no-gutter">
                            <a title="<?php echo $this->__('Add to Bag') ?>" href="<?php echo $this->getAddToCartUrl($_product) ?>"><span><span><?php echo $this->__('ADD TO BAG') ?></span></span></a>
                        <div class="more-info grid12-6 no-gutter">
                            <a title="<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>" href="<?php echo $_product->getProductUrl() ?>"><span><span><?php echo $this->__('MORE INFO') ?></span></span></a>
                    <?php else: ?>
                        <p class="availability out-of-stock grid-full"><span><?php echo $this->__('OUT OF STOCK') ?></span></p>
                    <?php endif; ?>

The code for addtocart (which is what I want for the category page) is: -

<?php $flag = $_product->getIsAffiliateProduct() ; ?>
<?php if ($flag ): ?>
<!-- beo affiliate product -->
 <div class="add-to-cart">
<?php $advertiserBuyURL = $_product->getAdvertiserBuyLink(); ?>
    <?php $buttonTitle = $this->__('Buy on Store'); ?>
    <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="redirectTo('<?php echo Mage::getBaseUrl().'/redirectTo.php?goto='.urlencode($advertiserBuyURL); ?>','<?php print $_product->getAdvertiserID(); ?>')" >
        <span><span><?php echo $buttonTitle ?></span></span>
    <?php echo $this->getChildHtml('', true, true) ?>
    <?php if($_product->getImpressionUrl() != "" ) : ?>
    <img src="<?php echo$_product->getImpressionUrl(); ?>" width="1" height="1" border="0"/>

How should I go about this?


All you need to do to achieve this is:

In your template that you posted replace the following lines:

<div class="add-to-bag grid12-6 no-gutter">
    <a title="<?php echo $this->__('Add to Bag') ?>" href="<?php echo $this->getAddToCartUrl($_product) ?>"><span><span><?php echo $this->__('ADD TO BAG') ?></span></span></a>

With the full snippet of text that you provided.

Now I would hope that at a very least you are moving the template files out from base/default into a theme for your project.

Then a more feature rich solution is to then move the entire logic out from the template and into a new block with its own template.. To do this you would need a new module with block that is responsible for isAffiliate. Then in the template file you could call the block. Via XML so add block to catalog_product_list and in template getChildHtml()

But depending on your skills and time the first solution will work.


$advertiserBuyURL = $_product->getAdvertiserBuyLink(); ?>

                            <a title="<?php echo $this->__('Buy Now') ?>" target="_blank" href="<?php echo Mage::getBaseUrl().'/redirectTo.php?goto='.urlencode($advertiserBuyURL).'&vendor_name='.$advertiser_id; ?>"><span><span><?php echo $this->__('BUY NOW') ?></span></span></a>

This worked. I paid a freelancer on oDesk.

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.