1
votes

My first post, i have code where i can individually remove add-to-cart options from products using an additional attribute in the back end, added in addtocart.phtml.

The problem i am having is that i do not want this to affect the add to cart button just the quantity box and label.

I have tried many variations and nothing seems to help, i am thinking that i have this code inserted in an incorrect file but i am not sure.

You can see the code below, i was wondering if anyone could assist me in amending this code in order to achieve the functionality that i am looking for:

<?php $_product = $this->getProduct() ?>
<?php $attTest= $_product->getData(); ?>
<?php if($attTest['sell_online']): ?>
    <?php if($_product->isSaleable()): ?>
        <div class="add-to-cart">
            <?php if(!$_product->isGrouped()): ?>
                <label for="qty"><?php echo $this->__('Number of weeks:') ?></label>
                <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo   $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>"  class="input-text qty" />
            <?php endif; ?>
            <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button   btn-cart" onclick="productAddToCartForm.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
            <?php echo $this->getChildHtml('', true, true) ?>
        </div>
    <?php endif; ?>
<?php endif; ?>

Any help with this would be much appreciated. thanks in advance.

3

3 Answers

2
votes

Set hints for template on to get .phtml and block class involved. Cross check if block class in local folder.

Also check if compiler mode is on in that case your file will be in inc class folder.

Once you make sure you have modify right file then : assuming that if $attTest sell online is the needed variable value.

 <?php if($attTest['sell_online']): ?>
    <label for="qty"><?php echo $this->__('Number of weeks:') ?></label>
    <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo          $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>"  class="input-text qty" />
 <?php endif; ?>
1
votes

I update this answer for any of the community members searching for this solution, my thanks go out to Satish the cleaver dude who helped me with my predicament and the original code provider who gave me the idea.

So firstly create an attribute so that you can turn quantity on and off (quantity_active), set catalog input type for store owner to yes/no.

Then copy and paste the following code over the code that exists in your addtocart.phtml.

<?php $_product = $this->getProduct() ?>
<?php $attTest= $_product->getData(); ?>
<?php if($_product->isSaleable()): ?>
<div class ="add-to-cart"></div>   
<?php if(!$_product->isGrouped()): ?>
<?php if($attTest['quantity_active']): ?>
<strong><label for="qty"><?php echo $this->__('Number of Weeks:') ?></label></strong>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty             ($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>" class="input-text qty" />
<?php endif; ?>
<div class ="clear"></div>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"       onclick="productAddToCartForm.submit()"><span><span><?php echo $this->__('Add to Cart') ?  ></span></span></button>

<?php echo $this->getChildHtml('', true, true) ?>

<?php endif; ?>
<?php endif; ?>

you should now be able to switch the quantity option on and off. :-)

0
votes

The other answer is great except that if any product doesn't have the attribute, an error will be thrown. Best to change the if test slightly:

<?php if (empty($attTest['quantity_active']) || false) :?>

This just checks to see if the attribute exists or is set for the product.