Disable add to cart if in quantity box is 0 - magento

I'm looking for solution for my problem. I have category list with add to cart button and quantity box. I need to disable add to cart when is in quantity box 0 and allow it when is 1 and more.
I need default value 0.
Now, when I click to add to cart button is added one product to the cart.
This problem is just in category list, not on product page.
My code from /app/design/frontend/theme/theme/template/catalog/product/list.phtml
<?php if ( !($product->getTypeInstance(true)->hasOptions($product)/*$_product->getData('has_options')*/ || $product->isGrouped()) ) : ?>
<div class="qty-holder">
<input type="text" name="qty" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="<?php echo $product->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<div class="qty-changer">
<i class="icon-up-dir"></i>
<i class="icon-down-dir"></i>
</div>
</div>
</form>
<?php $_productid == $_product->getId(); ?>
</i><span> <?php echo $this->__('Add to Cart') ?></span>
<?php else : ?>
<i class="icon-cart"></i><span> <?php echo $this->__('Add to Cart') ?></span>
<a href='<?php echo $this->getUrl('ajaxcart/index/options',array('product_id'=>$_product->getId()));?>' class='fancybox' id='fancybox<?php echo $_product->getId()?>' style='display:none'>Options</a>
<?php endif;?>
Any ideas?
Thanks!

Maybe something like this (javascript):
jQuery('.addtocart').each(function() {
var $self = jQuery(this),
oldOnClick = $self.attr('onclick'),
$product = $self.closest('.item');
$self.attr('data-onclick', oldOnClick).removeAttr('onclick');
$self.off('click').on('click', function() {
if($product.find('.input-text.qty').val() < 1)
return false;
else
eval(jQuery(this).data('onclick'));
});
});
When user clicks on 'add to cart', check if the quantity value is >= 1.
Edit: fix some things..

Put this condition to disable addtocart and add disabled="disbled" in anchor tag of add to cart
if($product->getProductDefaultQty() * 1 == 0){
<a disabled = "disabled"></a>
}
else{
// your normal code here for add to cart
}

Related

if click default button address should be default

One user multiple shipping address how to make it as default,if click the make as default button,that address should be default and remaining all address shown the make as default button in a particular address box,except default address box.
view page
<?php foreach ($buyer_Address as $row) { ?>
<div class="col-md-4">
<div class="panel panel-default add_min_height">
<div class="panel-heading">Default:</div>
<input type="hidden" name="de" id="de" value="<?php echo $row->b_id; ?>">
<div class="panel-body">
<address><?php echo $row->b_fullname; ?><br>
<?php echo $row->b_street_address; ?>,<?php echo $row->b_locality ?>,<br>
<?php echo $row->b_landmark; ?>,
<?php echo $row->b_city; ?>, <?php echo $row->b_state; ?>,<?php echo $row->b_pincode; ?>
India
Phone number: <?php echo $row->b_mobile_number; ?></address>
</div>
<div class="panel-footer">
<a href="<?php echo base_url(); ?>index.php/welcome/buyereditaddress?id=<?php echo $row->b_id; ?>" >Edit</a>
<i class="fa fa-ellipsis-v"></i>
Delete
<i class="fa fa-ellipsis-v"></i>
<?php if ($row->status == '0') { ?>
<button type="submit" style="color:#337ab7;background: none !important;border: none;" name="default" id="default">Make as deafault</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
controller
public function defaultAddress() {
$id = $this->input->post('de');
$this->BuyerProfile_Model->defaultAddress($id);
redirect('welcome/buyeraddresses');
}
model
function defaultAddress($id) {
$this->db->trans_start();
$this->db->query("UPDATE buyer_order_address SET status = '0' WHERE b_id = '$id'");
$this->db->query("UPDATE buyer_order_address SET status = '1' WHERE b_id = '$id'");
$this->db->trans_complete();
}

why Quantity is not updating along with the total price in cart page in magento 1.9.2?

I have used the follow code in checkout/cart page in my theme:
<?php foreach($this->getItems() as $_item): ?>
<hr>
</hr> <?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<?php echo $this->getChildHtml('form_before') ?>
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>
<fieldset>
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>"/>
<button type="submit" name="update_cart_action" value="update_qty" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Update Shopping Cart')); ?>" class="btnn4"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>
<script type="text/javascript">decorateTable('shopping-cart-table')</script>
</fieldset>
</form>
checkout/cart/item/default.phtml is remain same as it is in the base.When I adding some quantity in my cart page ..after clicking update button the page is reloading but the multiplied value with the quantity not showing and also quantity is remaining same.

How To show product quantity in dropdown Magento

I want to show Product quantity in dropdown like 10,20,30 for according to product in magento please help what are i do
please help
thanks
I would recommend you create a new numeric custom attribute for your products so you can define the packsize/order multiple for each product. Then go to this file;
app/design/frontend/YOURFOLDER/YOURTHEME/template/catalog/product/view/addtocart.phtml
In this file, find this code;
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="1<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php endif; ?>
And replace it with this;
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<?php
$qtymultiple = $_product->getData('your_attribute_code'); // Add your attribute_id here
if(($qtymultiple == 1) || (!$qtymultiple)) { // No need to anything ?>
<input type="text" name="qty" id="qty" maxlength="12" value="1<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php } else { //qty multiple requirement ?>
<select name="qty" id="qty" maxlength="12">
<?php
$countme = 1;
while ($countme < 101) { // Define how many multiples of the number to offer
echo '<option value="'.($qtymultiple*$countme).'">'.($qtymultiple*$countme).'</option>';
$countme++;
} ?>
</select>
<?php } ?>
<?php endif; ?>
This will show a select box with multiples instead of the free type qty box for products that have a value the custom attribute.

Magento - Let the user choose between exlude tax of include tax

I have a product with multiple options.
The user chooses how much he wants to pay for the product.
First I have created a dropdown box with the values €5,- €10,- etc.
The product price i have put to €0.
When I choose 10 euros, the product changes to 10 euros - that's good.
Now I want a checkbox where users can choose between Exclude Tax and Include Tax, so if I choose excluding tax the product will be inserted in the shopping cart as €10,00 witch is ok (excluding tax).
But when I choose Including tax the product needs to be inserted in the shopping cart as 10 /1.21 = €8,26 (excluding tax).
How can I make this possible?
EDIT:
I have the following code:
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
if (is_array($quote_item->getOptions())) {
foreach ($quote_item->getOptions() as $optionValue) {
echo ???? . ' --> ' . $optionValue->getValue() . '<br />';
}
}
This will give me the values from the options.
But how do I get the real option_id? I get the option_type_id now.
If you look to below page
app/design/frontend/default/default/template/catalog/product/price.phtml
you will find below code
<?php if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 0)): // including ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<span class="price-including-tax">
<span class="label"><?php echo $_taxHelper->__('Incl. Tax:') ?></span>
<span class="price" id="price-including-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_finalPriceInclTax+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 1)): // incl. + weee ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
to implement you can refer
Changing the price in quote while adding product to cart: magento

How to show configurable product stock status?

I have this phtml file which shows stock status:
<?php $_product = $this->getProduct() ?>
<?php $productQty = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<?php if ($productQty > 100): ?>
<div class="catalog-stock over-stock">
<span class="qry-text"><?php echo $this->__('In stock:'); ?></span>
<span class="qry-count">100+</span>
</div>
<?php elseif ($productQty > 0 && $productQty <= 100): ?>
<div class="catalog-stock normal-stock">
<span class="qry-text"><?php echo $this->__('In stock:'); ?></span>
<span class="qry-count"><?php echo $productQty; ?></span>
</div>
<?php elseif ($deliveryDate = $_product->getStockDeliveryDate()): ?>
<div class="catalog-stock no-stock">
<span class="qry-text"><?php echo $this->__('Expected'); ?></span>
<span class="qry-count"><?php echo $deliveryDate; ?></span>
</div>
<?php elseif ($_product->getTypeId() != 'configurable' && $_product->getTypeId() != 'grouped' && $_product->getTypeId() != 'bundle'): ?>
<div class="catalog-stock no-stock">
<span class="qry-text"><?php echo $this->__('Expected'); ?></span>
<span class="qry-count"><?php echo $this->__('n/a'); ?></span>
</div>
<?php endif; ?>
I call it with this line <?php echo $this->getChildHtml('product_type_data') ?> from product/view/view.phtml
When used with simple product it works perfectly, but how to do same thing with configurable product?
What I want is to change stock status depending on what configurations is selected.
One solution is to check if product is configurable and then display all values at same time and hide with css. But if I do this I have problem - how to know which product is selected and show it's stock status?
I guess best option would be to do this with ajax, but I spent hours trying to do that and didn't succeed.

Resources