1: <?php
2:
3: /**
4: * ShipSync
5: *
6: * @category IllApps
7: * @package IllApps_Shipsync
8: * @copyright Copyright (c) 2014 EcoMATICS, Inc. DBA IllApps (http://www.illapps.com)
9: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10: */
11:
12: /**
13: * IllApps_Shipsync_Model_Sales_Quote_Address
14: */
15: class IllApps_Shipsync_Model_Sales_Quote_Address extends Mage_Sales_Model_Quote_Address
16: {
17:
18:
19: /**
20: * validate
21: *
22: * @return mixed
23: */
24: public function validate()
25: {
26: // Get address validation model
27: $fedexAddress = Mage::getModel('usa/shipping_carrier_fedex_address');
28:
29: // If shipping address
30: if ($this->getAddressType() == 'shipping')
31: {
32: // If street is present
33: if ($this->getStreet(-1))
34: {
35: // If PO Box filtering is enabled and street is a PO Box
36: if (Mage::getStoreConfig('carriers/fedex/filter_po_boxes') && $fedexAddress->isPostOfficeBox($this->getStreet(1)))
37: {
38: return array(Mage::helper('customer')->__("We're sorry, we do not ship to PO Boxes."));
39: }
40:
41: // If country is US and address validation is enabled
42: if ($this->getCountryId() == 'US' && Mage::getStoreConfig('carriers/fedex/address_validation'))
43: {
44: // Validate address
45: $fedexAddress->validate($this);
46:
47: // Check for error
48: if ($fedexAddress->getAddressResultError())
49: {
50: return $fedexAddress->getAddressResultError();
51: }
52: }
53: }
54: }
55:
56: // Return true for all other addresses
57: return true;
58: }
59:
60:
61: /**
62: * Collecting shipping rates by address
63: *
64: * @return Mage_Sales_Model_Quote_Address
65: */
66: public function collectShippingRates()
67: {
68: $this->setCollectShippingRates(false);
69:
70: $this->removeAllShippingRates();
71:
72: if (!$this->getCountryId()) {
73: return $this;
74: }
75:
76: $found = $this->requestShippingRates();
77: if (!$found) {
78: $this->setShippingAmount(0)
79: ->setBaseShippingAmount(0)
80: ->setShippingMethod('')
81: ->setShippingDescription('');
82: }
83:
84: return $this;
85: }
86: }
87: