1

plese visit configurable product: here i am using following code to display "BUY NOW" button.

template path hint : here

is there any way to hide the "BUY NOW" button for configurable products

app/design/frontend/default/default/template/mpassignproduct/catalog/product/view/addtocart.phtml

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <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" />
        <?php endif; ?>
        <?php
            $assignPro=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($_product->getId());
        ?>
        <?php if($assignPro['assignCount']): ?>
            <?php if($assignPro['sellerqty'] > 0): ?>

                <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>

                <div style="clear: both; padding-top: 10px;">
               <button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="button buy-now btn btn-block btn-express-buynow"><span><span>Buy Now</span></span></button>
            </div>

            <?php endif; ?>
        <?php else: ?>
            <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><i class="fa fa-shopping-cart"></i><?php echo $buttonTitle ?></span></span></button>

            <div style="clear: both; padding-top: 10px;">
                <button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="button buy-now btn btn-block btn-express-buynow"><span><span>Buy Now</span></span></button>
            </div>

        <?php endif; ?>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
  • Hi, can you share how did you manage to create this buy now button? Any other codes and files to add? Thanks! – KiD Cajes May 21 '16 at 9:33
  • @KiDCajes check this link – user39789 May 23 '16 at 5:26
  • @nsdlfefinedieicbe thanks for the link but this one doesn't have validation for items with custom option or configurable. – KiD Cajes May 23 '16 at 6:55
  • @KiDCajes than its better if you create new question with that you followed this link and you wanted custom option or configurable. – user39789 May 23 '16 at 6:59
  • I already did but no one seems replying sad magento.stackexchange.com/questions/116365/… – KiD Cajes May 23 '16 at 7:24
0

Try this:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <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" />
        <?php endif; ?>
        <?php
            $assignPro=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($_product->getId());
        ?>
        <?php if($assignPro['assignCount']): ?>
            <?php if($assignPro['sellerqty'] > 0): ?>

                <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
            <?php if($_product->getTypeId() != 'configurable'):?>
                <div style="clear: both; padding-top: 10px;">
               <button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="button buy-now btn btn-block btn-express-buynow"><span><span>Buy Now</span></span></button>
            </div>
           <?php endif;?>

            <?php endif; ?>
        <?php else: ?>
            <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><i class="fa fa-shopping-cart"></i><?php echo $buttonTitle ?></span></span></button>

          <?php if($_product->getTypeId() != 'configurable'):?>
            <div style="clear: both; padding-top: 10px;">
                <button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="button buy-now btn btn-block btn-express-buynow"><span><span>Buy Now</span></span></button>
            </div>
         <?php endif;?>

        <?php endif; ?>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>

We are checking product's type and act accordingly.

<?php if($_product->getTypeId() != 'configurable'):?>

Hope this helps.

  • Fatal error: Uncaught Error: Call to a member function getAssignProDetails() on boolean – Andhi Irawan Jul 15 at 23:26
  • 1
    getAssignProDetails is a function only exist in OP's module. You will need to remove all of those related dependencies. – Adarsh Khatri Jul 15 at 23:36
  • thank you Adarsh.I have followed your advice and have succeeded.is there a way for the Buy Now button after clicking it will be directed to the Shopping Cart page? – Andhi Irawan Jul 16 at 1:06
  • but I have turned off the "after adding a product redirect to shopping cart" feature so that Add To Cart is not directed to the Shoppping Cart page. So there are 2 buttons : Buy Now button and the Add To Cart button. The Buy Now button will be directed to the Shopping Cart page, and the Add To Cart button remains on the page. – Andhi Irawan Jul 18 at 17:36

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.