I got some code while searching for hide add to cart button at category products but i am not able to set this below code to my given List.phtml, Please guide me.
Now we will hide the ‘Add to Cart’ button on category list page. Open /app/design/frontend/default/themeXXX/template/catalog/product/list.phtml file and look for the following code:
<?php
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
echo '<span class="login_for_details" style="float:left"><strong>Login to Add to Cart</strong></span>';
} else { ?>
My website list.phtml
<?php if ($product->isSaleable()) : ?>
<?php if ( !($product->getTypeInstance(true)->hasOptions($product) || $product->isGrouped()) ) : ?>
<?php if(!Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)):?>
<form id="addtocart_form_<?php echo $_product->getId(); ?>" action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
<?php endif; ?>
<div class="qty-field">
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<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>
</div>
<?php if (!Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)) :?>
</form>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
If your changing in your core code then add the below code in your List.phtml
<?php $session = Mage::getSingleton('customer/session', array('name' => 'frontend')); ?>
<?php if($session->isLoggedIn()) { ?>
//Your Add to Cart Button Html
<?php } else { ?>
// Your Login to Add to Cart Html
<?php } ?>
Put the above code everywhere on your frontend where your products are displaying.
Related
I am developing a store and the product I tried to add is a grouped product which I had done some design and configuration on the front end. Then, I added sample grouped product and when I click "Add to cart" , there is message "Please specify the quantity of product(s)."
Please see the website (Sorry the website is in Thai but you can try to increase the Quantity of each product and then click add to cart - Pink button)
http://www.preciosathailand.com/eyeline-0001.html
This is PHP code that I made the configuration
<?php if ($_hasAssociatedProducts): ?>
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td width="80%"><span class="product-<?php echo $_item->getId() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></span></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php echo $this->getTierPriceHtml($_item) ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<td class="a-center" width="20%">
<?php if ($_item->isSaleable()) : ?>
<div class="qty-tools">
<div class="minus-qty minus-<?php echo $_item->getId() ?>"><a class="click-to-minus" id="minus-<?php echo $_item->getId() ?>" href="#" data-id-p="<?php echo $_item->getId() ?>">-</a></div>
<div class="input-qty-wrapper">
<input type="text" name="super_group[<?php echo $_item->getId() ?>]" data-qty-product-id="<?php echo $_item->getId() ?>" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
</div>
<div class="plus-qty plus-<?php echo $_item->getId() ?>"><a class="click-to-plus" href="#" id="plus-<?php echo $_item->getId() ?>" data-id-p="<?php echo $_item->getId() ?>">+</a></div>
</div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
</tr>
<?php endif; ?>
This is jQuery that I have done.
jQuery(document).ready(function(){
jQuery('.click-to-minus').click(function(){
var IDInput = jQuery(this).data('id-p');
var CurrentVal = jQuery('input[name="super_group['+IDInput+']"]').val();
var minusedVal = CurrentVal-1;
jQuery('input#'+IDInput).val(minusedVal);
});
jQuery('.click-to-plus').click(function(){
var pIDInput = jQuery(this).data('id-p');
var CurrentPlusVal = jQuery('input[name="super_group['+pIDInput+']"]').val();
/* if ( CountPlus == 0){
var plusedVal = 1;
}else{
jQuery('input#'+pIDInput).val('');
var plusedVal = CurrentPlusVal+1;
}*/
var plusedVal = +CurrentPlusVal+1;
jQuery('input[data-qty-product-id="'+pIDInput+'"]').val(plusedVal);
});
});
Did I do anything wrong?
Are you trying to group configurable products, then you should know that magento doesnt allow it.
you can check this answer here
I am running Magento v1.9.0.1. I want to disable Cash on Delivery for specific products. I have installed COD extension from magento commerce.
I am new to Magento structure and no nothing to little about it. Tried some debugging on it but it is going up above my head.
Also, I have search every where over the internet but no one has ever provided the code for Magento v1.9.0.1.
Create a custom attribute with attribute code as cod and assign it to General of attribute sets.
Now as per you requirement change your methods.phtml (if there is no custom code included in this) as follows.
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<dt>
<?php
//cod verification starts
$attr_cod = array();
$cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach ($cartItems as $item) {
$attr_cod[] = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getCod();
}
if(in_array('1', $attr_cod) && $_code == 'cashondelivery') {continue; }
//cod verification ends
?>
<?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>
<span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
<?php $oneMethod = $_code; ?>
<?php endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php endforeach;
endif;
?>
<?php echo $this->getChildChildHtml('additional'); ?>
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
<?php if (is_string($oneMethod)): ?>
payment.switchMethod('<?php echo $oneMethod ?>');
<?php endif; ?>
//]]>
</script>
I have tested this and works fine.
COD is already in magento you didn't need to install it.
There are two way
create a new config setting in which you can enter ids of products
for which you didn't want COD option.
You can create product attribute too for checking COD option.
and check these ids (if you create config settings ) with the
product id or check for the product attribute on
app\design\frontend\base\default\template\checkout\onepage\payment\methods.phtml.
And by simple if else conditions you can avoid COD option for these
products.
I'm using joomla and I have begun to develop a web app, I want to get values from form fields. Normally I use $_POST but this page didn't work.
This is my default.php >>>
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>
<div class="item" <?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<form id="add-item" action="<?php echo JRoute::_('index.php?option=com_stationery&task=item.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
<fieldset>
<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.
?>
<legend><?php echo JText::_($fieldset->label);?></legend>
<?php endif;?>
<dl>
<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
<?php if ($field->hidden):// If the field is hidden, just display the input.?>
<?php echo $field->input;?>
<?php else:?>
<dt>
<?php echo $field->label; // Show label for registor ?>
<?php if (!$field->required && $field->type!='Spacer'): ?>
<?php endif; ?>
</dt>
<dd><?php echo ($field->type!='Spacer') ? $field->input : " "; ?></dd>
<?php endif;?>
<?php endforeach;?>
</dl>
</fieldset>
<?php endif;?>
<?php endforeach;?>
<div>
<button name="save" type="submit" class="btn btn-success" class="validate"><?php echo JText::_('Save');?></button>
<?php echo JText::_('or');?>
<a class="btn btn-danger" href="<?php echo JRoute::_('/stationery/index.php/add-items');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
<input type="hidden" name="option" value="com_stationery" />
<input type="hidden" name="task" value="item.save" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
<script>
This is loop from field.xml to show each field. I want to get value in that inputbox. now I can get to javascript variable but I can't use to save in my table. I want php variable ($....). How can I get it? Please help me. Thank you
In Joomla 2.5+ you could use JRequest, but since it's deprecated you should:
JFactory::getApplication()->input->get...
however looking at your code there may be a simpler approach just bind the input to the table model
Here is my code, it basically grabs $banners and displays them out, there are 2 at the moment, however , it stops after the first one and displays out the html div id="footerNews... etc and carries on again after that. This is correct...
<?php if ($banners) { $i = 1; ?>
<div id="footerBanners">
<?php foreach ($banners as $banner) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php if ($i == 1) { ?>
<div id="footerNewsletter">
<p>Newsletter Sign Up</p>
Go
<input type="text" name="email" placeholder="Email address" />
</div>
<div id="footerEvents"><?php echo $text_events; ?></div>
<?php } ?>
<?php $i++; } ?>
</div>
<?php } ?>
The problem is that some of variables in $banners dont actually have a link. To get around this, I attempted to put an if statement in to not display <a href> if there is no link. however this messes up the order that of the content, its important that I keep the content in the correct order as above ^. Here was my attempt.
<?php if ($banners) { $i = 1; ?>
<div id="footerBanners">
<?php foreach ($banners as $banner) { ?>
<?php if ($banner['link'] == '') { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /><?php }
else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /><?php } ?>
<?php } ?>
<?php if ($i == 1) { ?>
<div id="footerNewsletter">
<p>Newsletter Sign Up</p>
Go
<input type="text" name="email" placeholder="Email address" />
</div>
<div id="footerEvents"><?php echo $text_events; ?></div>
<?php } ?>
<?php $i++; } ?>
</div>
While the code does what it says its supposed to do, its not displaying the correct order anymore, its displaying the 1 linkable $banner then the html, and THEN the image(ie the second $banner with no link. However I need it to display in the same layout as the first bit of code.
Here is the outputted html code, although the image is appearing last on the site.
<div id="footerBanners">
<img src="http://mysite.com/image/data/banner4.jpg" alt="Free Delivery" />
<img src="http://mysite.com/image/data/banner5.jpg" alt="Gift Vouchers" /> <div id="footerNewsletter">
<p>Newsletter Sign Up</p>
Go
<input type="text" name="email" placeholder="Email address" />
</div>
<div id="footerEvents">EVENTS</div>
</div>
Any pointers?
<?php if ($banners) {
echo '<div id="footerBanners">';
foreach ($banners as $banner) {
if ($banner['link'] == '') {
echo '<img src="'.$banner['image'].'" alt="'.$banner['title'].'" />';
}
else {
echo '<img src="'.$banner['image'].'" alt="'.$banner['title'].'" />';
}
if ($first_banner != 'displayed') {
echo '<div id="footerNewsletter">
<p>Newsletter Sign Up</p>
Go
<input type="text" name="email" placeholder="Email address" />
</div>
<div id="footerEvents">'.$text_events.'</div>';
$first_banner = 'displayed';
}
}
echo '</div>';
}
?>
Is there a way to echo the short description foreach related product?
I've tried to use this code but it doesn't display the description of each product:
<?php echo nl2br($this->getProduct()->getDescription()) ?>
also
<?php echo $_helper->productAttribute($_item, nl2br($_item->getShortDescription()), 'short_description') ?>
Is there a way to do this for related products? If anyone knows please point me in the right direction.
<?php if($this->getItems()->getSize()): ?>
<div class="block block-related">
<div class="block-title">
<strong><span><?php echo $this->__('Related Products') ?></span></strong>
</div>
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Check items to add to the cart or add to your wishlist') ?> <br /></p>
<div class="form-horizontal">
<?php foreach($this->getItems() as $_item): ?>
<div class="control-group">
<label for="related-checkbox<?php echo $_item->getId() ?>" class="control-label">
<a class="fancybox static-thumbs pull-left" href="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(500, 450); ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(135, 135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
</label>
<div class="controls">
<label class="checkbox">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
<?php endif; ?>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<span class="icon-check"></span>
<p class="product-name span6">
<?php echo $this->htmlEscape($_item->getName()) ?>
<br />
<?php echo nl2br($this->getProduct($_item)->getDescription()) ?>
</p>
<form action="<?php echo $this->getAddToCartUrl($_item) ?>" method="post">
<fieldset>
<label class="product-name"><?php echo $this->__('Quantity:'); ?></label>
<select name="qty" class="span1">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getMaxSaleQty()) ?>
</select>
<div class="clearfix"></div>
<button class="btn btn-danger" data-loading-text="PLease wait..."><span><?php echo $this->__('Add to Cart') ?></span></button>
<span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
</fieldset>
</form>
<?php endif; ?>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
</label>
</div>
</div>
<hr />
<?php endforeach ?>
</div>
</div>
Have you tried nl2br($this->getProduct($_item)->getShortDescription()) ?
It might be that the value for short description isn't loaded for related products by default. You could try to do a $_item->load($_item->getId()) and then use $_item->getShortDescription().
after TRYING $_item->load($_item->getId()) and echoing the shortDescription, you should look for the Collection where the related products are loaded. In this collection the attribute short_description is not loaded with.
If you load every product, you make a lot of queries to the database which will cost a lot of performance. This is not needed. The alternative is:
$relatedProductCollection->addAttributeToSelect('short_description');
The question is to find the $relatedProductCollection.
UPDATE:
I dug into the code (Reference is v. 1.7.0.2):
// app/code/core/Mage/Catalog/Block/Product/List/Related.php:61
$this->_addProductAttributesAndPrices($this->_itemCollection);
// app/code/core/Mage/Catalog/Block/Product/Abstract.php:410
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
// app/code/core/Mage/Catalog/Model/Config.php:260
$this->getAttributesUsedInProductListing()
This should be interpreted as: When the "related products" are loaded, all attributes are loaded, which are used in the product listing as well. The problem might be: short_desciption is loaded by default. So remove the load() call and check, wether the attribute short_description is "Used in Product Listing". If this is set to yes, My interpretation is wrong.
None the less, the solution by loading every product is crap.
EDIT:
I have added the following line to Related.php
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToSelect('short_description')
->setPositionOrder()
->addStoreFilter()
And using this line does echo a descrtiption foreach product but it is the Same description getProduct()->getDescription()) ?>
You need to <?php echo ($this->getProduct()->getShortDescription()) ?>
But editing the core code is a bad way to change the magento behaviour as well. Here is described how to rewrite a block, but I don't think this is necessary. http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/