0

On the product page, I want to remove the Incremental Quantity option buttons if a given attribute in that product is "Yes". In this case product attribute "ddq_enabled" must be set to "Yes" for the Incremental Quantity option not to be desired.

I'm new to php so I do not know what syntax to use but I pretty much want to create an if statement

If ddq_enabled is yes, then only show the add to cart button.

If ddq_enabled is no, then we can default to the regular view

Below is my phtml file - I'm sure this is an easy one. Thank you...

 <?php

?>
<?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>
        <div class="qty-button"> 

                <div class="box-icon button-minus">
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty ) &amp;&amp; qty &gt; 0 ) qty_el.value--;return false;" class="qty-decrease" />
                </div>
                <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 class="box-icon button-plus"> 
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" class="qty-increase " />
                </div>  


        </div>      
        <?php endif; ?> 
        <button type="button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> <span><?php echo $buttonTitle ?></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
  • Did one of the answers helped you get the job done? – Badger Oct 9 '15 at 13:11
0

try this

This Logic

<?php 

     if($_product->getAttributeText('ddqenabled')=='Yes')
    {
      <!-- Your display code -->
    }
    else {
            <!-- your else part code -->
           }
     ?>

Your try this

<?php

?>
<?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>

        <?php if($_product->getAttributeText('ddqenabled')=='Yes'){?>
        <div class="qty-button"> 

                <div class="box-icon button-minus">
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty ) &amp;&amp; qty &gt; 0 ) qty_el.value--;return false;" class="qty-decrease" />
                </div>
                <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 class="box-icon button-plus"> 
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" class="qty-increase " />
                </div>  
<?php }

 else {?>
<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 }?>


        </div>      
        <?php endif; ?> 
        <button type="button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> <span><?php echo $buttonTitle ?></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
|improve this answer|||||
0

First get the value of your attribute:

<?php $ddqenabled = $_product->getDdqEnabled(); ?>

Surround the piece of code that should be shown if ddq_enabled is "no" with an if statement:

<?php if($ddqenabled == 0) : ?>
  *** Your piece of code ***
<?php endif; ?>

If Ddq is enabled the attribute will return a "1" and your increment section will be skipped.

Basically your code could look like this:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php $ddqenabled = $_product->getDdqEnabled(); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
    <?php if(!$_product->isGrouped() && ($ddqenabled == 0)): ?>
    <label for="qty"><?php echo $this->__('Qty:') ?></label>
    <div class="qty-button"> 

            <div class="box-icon button-minus">
                <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty ) &amp;&amp; qty &gt; 0 ) qty_el.value--;return false;" class="qty-decrease" />
            </div>
            <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 class="box-icon button-plus"> 
                <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" class="qty-increase " />
            </div>  


    </div>      
    <?php endif; ?> 
    <button type="button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> <span><?php echo $buttonTitle ?></span></button>
    <?php echo $this->getChildHtml('', true, true) ?>
</div>
|improve this answer|||||

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.