Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created June 12, 2013 14:54
Show Gist options
  • Save ryaan-anthony/5766009 to your computer and use it in GitHub Desktop.
Save ryaan-anthony/5766009 to your computer and use it in GitHub Desktop.
<?php
class Ip_Prohibited_Model_Onepage extends Mage_Checkout_Model_Type_Onepage
{
protected $Restricted_Countries = array(
'GB', // Country Codes
'CA'
);
protected $Restricted_Categories = array(
20, // Category IDs
30,
40
);
protected $Error_Message = 'Shipping of these products are not available for this country.';
public function saveShippingMethod($shippingMethod)
{
$quote = $this->getQuote();
$country = $quote->getShippingAddress()->getCountry();
if(in_array($country, $this->Restricted_Countries)){
foreach ($quote->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
foreach ($this->Restricted_Categories as $cat_id) {
if(in_array($cat_id, $product->getCategoryIds())){
Mage::getSingleton('checkout/session')->addError($this->Error_Message);
Mage::throwException($this->Error_Message);
exit();
}
}
}
}
return parent::saveShippingMethod($shippingMethod);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment