Jump to content

Cash on Delivery by product attribute


Seirios

Recommended Posts

I would like to change the following code on cashondelivery.php so during checkout if a product has attribute id 1 and  value id 2 (inside the attribute id 1) the Cash on delivery option is automatically disabled.

 

As attribute id 1 i have created a group called "Warehouse"

As value id 2 i have created a value called "China"

 

------------------------------------------------------------------------
public function hookPayment($params) {
 
if (!$this->active)
return ;
 
global $smarty;
global $cart;
 
// Check if cart has product download
if ($this->hasProductDownload($params['cart']))
return false;
 
$smarty->assign(array(
'this_path' => $this->_path, //keep for retro compat
'this_path_cod' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
 
// list of all products, which can't be bought by cash on delivery method
$disable_cod = array(7, 20, 22);
 
// get all cart products
$products = $cart->getProducts();
 
// default value - show module
$show = true;
 
// loop through all products and check if
foreach ($products as $product) {
 
if (in_array($product['id_product'], $disable_cod))
$show = false; // cash on delivery is not allowed, hide it
 
}
 
// hide module, if cart contains any product from $disable_cod array above
if (!$show)
return ;
else
return $this->display(__FILE__, 'payment.tpl');
 
}
----------------------------------------------------------------------------------
 
Thanks in advance

 

Link to comment
Share on other sites

Dear Krystian

 

Thank you for your solution.

I seems to be working on my test site but not on my normal site (COD keeps showing no matter what).

Both sites are identical (P.S 1.6.0.9)

On my normal site i only have Greek language installed with language ID 2, English language ID 1 is deleted.

On my test site i have both English ID 1 and Greek ID 2.

Maybe the language ID is the problem?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...