Magento Expert Forum - Improve your Magento experience

Results 1 to 3 of 3

PHP else: statements in addtocart.phtml - Adding conditions to the Add To Cart button

  1. #1
    New member
    Join Date
    Mar 2015
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP else: statements in addtocart.phtml - Adding conditions to the Add To Cart button

    My store has the options for user to Add To Cart, Call To Order, Visit Our Store.

    I've modified the category page (list.phtml) to show "View Product" instead of Add to Cart.

    On the product page, now, I need the options that my store will offer users, as stated in the first sentence. I've created attributes for these products with yes/no options when they make products. Attrib names are 'call_to_order' and 'visit_our_store' . What I'd like to do is on the addtocart.phtml add code to look if this product has one of those attribs as yes and then show the appropriate button, replacing the normal 'Add To Cart' with the appropriate text , and preferably no action to be taken when they click the button. I'd still like it to have the same styling as the 'Add to Cart' button.

    I assume this can be done using get attrib and else php, my php is very rusty and I'm not sure where to put it/how to write it.

    Current addtocart.phtml:

    Code:
    <?php $_product = $this->getProduct(); ?>
    <?php $buttonTitle = $this->__('Add to Cart'); ?>
    <?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
            <div class="qty-block">
                <label for="qty"><?php echo $this->__('Qty:') ?></label>
                <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
            </div>
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
    <?php endif; ?>
    If there are other changes that would need to be made, please advise. I haven't found a solution to this on the web. Even some of the extensions that I think might work would involve custom coding as well imho. This seems like a pretty straight forward solution to my problem.

    Thank you!

    View more threads in the same category:


  2. #2
    Junior Member johny_ng's Avatar
    Join Date
    Nov 2013
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Can you show me the current result html of this code?

  3. #3
    New member
    Join Date
    Mar 2015
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for the reply - I've since created a solution to this problem. I won't post it here, as the real solution was not related to this file at all, but other files and my fix is not a true fix. It will work for now, until I wish to have a more full featured site. Corners were cut to maintain deadlines. Thank you!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •