Created
June 12, 2013 14:54
-
-
Save ryaan-anthony/5766009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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