Good morning I installed Magento ver. 1.9.2.1 and I need to delete the box quantity only on some products. I was thinking, for example, when max quantity is set to 1, instead for other products leave the box. Thank you, do you have any suggestions?
Nicola
I tried to modify the file addtochar.phtml but without success. I attach the code
?>getProduct(); ?> ('Add to Cart'); ?> isSaleable()): ?> isGrouped()): ?> __('Qty:') ?> getProductDefaultQty() * 1 ?>" title="quoteEscape($this->('Qty')) ?>" class="input-text qty" /> " id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> getChildHtml('', true, true) ?> showButtonDesign(); ?>
I hope this code will help you.
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<?php $hiddenFlag = in_array($_product->getId(), array(10,20,30,40)) ? true : false; ?>
<?php if (!$hiddenFlag): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<?php endif;?>
<input type="<?php echo $hiddenFlag ? 'hidden' : 'text' ?>" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
<?php endif; ?>
<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 echo $this->getChildHtml('', true, true) ?>
</div>
Please pay attention to this line: <?php $hiddenFlag = in_array($_product->getId(), array(10,20,30,40)) ? true : false; ?> it will check if product eligible for a qty visibility.
Related
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.
Is there a way to sort products by any custom attribute? For example, sort by category, brand or colour?
I assume that I should create the attribute and set it to be "Used for Sorting in Product Listing".
I would like to sort products by the following attributes:
gender first, then brand, category and lastly colour.
The question is how do I use these attributes to sort the products in the backend so that they are visible in the frontend in that order?
You can use this code
Create a phtml file (sort.phtml) under catalog\product\list.
Contain of sort.phtml is
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" class="v-middle" />
<?php else: ?>
<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" class="v-middle" />
<?php endif; ?>
</div>
After that call this file in list.phtml using below codes-
echo $this->getLayout()->createBlock("catalog/product_list_toolbar")->setTemplate('catalog/product/list/sort.phtml')->toHtml();
Hope this code will be working
In MAGENTO,When viewing products in the category view, I would like to be able to have a “Quantity” box that allows the user to enter the quantity needed before clicking the “Add to Cart” button. How can I show this?
In List.phtml file find the below line
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
and replace it with
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?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->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
I'm new for Magento. I need to display latest added product in home page. I'm using following code in 2columns-left.phtml
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
<?php
$productsCollection = Mage::getModel("catalog/product")->getCollection()
->addAttributeToSort("entity_id","DESC")
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
->setPageSize(6)
->setCurPage(1);
foreach ($productsCollection as $product) {
$model = Mage::getModel('catalog/product')->load($product->getId());
echo $model->getName().'<br>';
echo $model->getPrice().'<br>';
echo $model->getImageUrl().'<br>';
echo "<br><br>";
}
?>
</div>
</div>
It's working fine. But I can't correct code for add-to-cart option.
I found fllowing code from addtocart.phtml with script,
<?php $_product = $this->getProduct(); ?>
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form">
<?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; ?>
<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; ?>
</form>
But, if I click add-to-cart, going to home page.
Help me.
Call a block on home page through static block with content value as
{{block type="catalog/product_list" name="product_listing" template="catalog/product/latest.phtml"}}
or you can directly call this block on cms home , paste this
{{block type="catalog/product_list" name="product_listing" template="catalog/product/latest.phtml" }}
in your cms home page content.
create a file in folder frontend/theme_folder/default/template/catalog/product as latest.phtml.
Paste the below code in it as :
Latest Products
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 4);
?>
<?php $_iterator = 0; ?>
<ul class="products-grid">
<?php foreach($_productCollection as $_product) : ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></h2>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
Thats it you will be able to see the latest 4 product on home page. you can increase the number of product by increasing the ->setPage(1, 4); to your required number of product on home page.
Today i started working in registration form in magento site. As you know by default it's having gender drop down. I need to change that to checkbox.
So far i went to register.phtml file, and tried to add <input type="radio" ...../> select files, but this didn't worked.
Did anyone know how to solve this !
please give me some suggestions to so this....
Do not forget the validation!
<div class="input-box">
<?php
$options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
$value = $this->getGender();
$_last = count($options);
$_index = 0;
?>
<?php foreach ($options as $option):?>
<?php if($option['value'] != ''): ?>
<input id="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>"
class="radio<?php if ($this->isRequired() && $_index == $_last - 1):?> validate-one-required<?php endif; ?>"
type="radio" title="<?php echo $option['label'] ?>"
value="<?php echo $option['value'] ?>" name="<?php echo $this->getFieldName('gender')?>"
<?php if ($option['value'] == $value) echo ' checked="checked"' ?>>
<label for="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>">
<?php echo $option['label'] ?>
</label>
<?php endif; ?>
<?php $_index++; ?>
<?php endforeach;?>
</div>
Magento uses widgets on registration form. In fact in template register.phtml you can see lines:
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
<?php if ($_gender->isEnabled()): ?>
<li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
<?php endif ?>
This particular widget can be found in template/customer/widget directory. So in order to change select into radio buttons, copy it (template) to your theme and modify, e.g.:
<div class="input-box">
<label><?php echo $this->__('Gender'); ?></label>
<?php $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();?>
<?php $value = $this->getGender();?>
<?php foreach ($options as $option):?>
<input type="radio" name="<?php echo $this->getFieldName('gender')?>" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' selected="selected"' ?> /><?php echo $option['label'] ?>
<br />
<?php endforeach;?>
</div>
Hope didn't make any typo.