Disable Cash on Delivery for specific products - php

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.

Related

Grouped Product won't be added to cart and there is a message "Please specify the quantity of product(s)."

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

Hide add to cart for Guest User in Magento

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.

If statment to only show one value from an array

I am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code

select option in payment method instead of radion button in magento

This is my methods.phtml file in onepagecheckout in magento,I want the dropdown(select option) button instead of radio button .........so that i could select the payment method to pay the payment.
<?php if (!$methods = $this->getMethods()) : ?>
<p><?php echo $this->helper('checkout')->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else : ?>
<dl class="sp-methods">
<?php foreach ($this->getMethods() as $_method): $_code = $_method->getCode() ?>
<dt>
<?php if( sizeof($this->getMethods()) > 1 ): ?>
<input value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_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 endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->htmlEscape($_method->getTitle()) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
//]]>
</script>
<?php endif; ?>
You can do the select option dropdown for payment method as setup below code in methods.phtml file.
Also you have to changes in opcheckout.js line no 715 to change "elements[i].checked" to "elements[i].value".
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
?>
<dt>Select Payment Method:</dt>
<select name="payment[method]" onchange="payment.switchMethod(this.value);">
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<option id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" <?php if($this->getSelectedMethodCode()==$_code): ?> selected="selected"<?php endif; ?>>
<?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?>
</option>
<?php endforeach; ?>
</select>
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd id="dd_method_<?php echo $_code ?>">
<?php echo $html; ?>
</dd>
<?php endif;
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 used this one to get my select list if helpful
<?php
$ptId1=mysql_query(" some query here")
echo"<select name=ptId>";
while($ptId=mysql_fetch_array($ptId1))
{
echo '<option value="'.$ptId['id'].'">'.$ptId['id'].'</option>';
}
echo '</select>';?>
}

Arrange the payment options in checkout

I am trying to edit the layout of payment options in magento that are in the
path:- **/template/checkout/onepage/payment/methods.phtml
<dl class="sp-methods" id="checkout-payment-method-load">
<?php foreach ($this->getMethods() as $_method): $_code = $_method->getCode(); ?>
<dt class="p_method">
<?php if( sizeof($this->getMethods()) > 1 ): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_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 endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $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; ?>
</dl>
How could I change the order from the getMethods() array ?
You can set the order of payment methods from admin directly where every payment method has a order field that you can set
system > configuration > sales > payment methos

Categories