pitneybowes_gsp - Version 1.0.0

Version Notes

Initial Stable GSP release for Magento Connect.

Download this release

Release Info

Developer Raymond Lai
Extension pitneybowes_gsp
Version 1.0.0
Comparing to
See all releases


Code changes from version 0.9.0 to 1.0.0

Files changed (38) hide show
  1. app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Invoice/Totals.php +25 -17
  2. app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Totals.php +26 -17
  3. app/code/local/Pb/Pbgsp/Block/Checkout/Shipping/Method/Available.php +76 -67
  4. app/code/local/Pb/Pbgsp/Block/Form.php +60 -77
  5. app/code/local/Pb/Pbgsp/Block/Sales/Order/Invoice/Totals.php +23 -14
  6. app/code/local/Pb/Pbgsp/Block/Sales/Order/Totals.php +56 -35
  7. app/code/local/Pb/Pbgsp/Model/Api.php +452 -443
  8. app/code/local/Pb/Pbgsp/Model/Carrier/ShippingMethod.php +304 -298
  9. app/code/local/Pb/Pbgsp/Model/Catalog/Category.php +145 -128
  10. app/code/local/Pb/Pbgsp/Model/Catalog/Cron.php +102 -95
  11. app/code/local/Pb/Pbgsp/Model/Catalog/File.php +728 -673
  12. app/code/local/Pb/Pbgsp/Model/Catalog/Product.php +204 -198
  13. app/code/local/Pb/Pbgsp/Model/Credentials.php +128 -114
  14. app/code/local/Pb/Pbgsp/Model/Creditmemo/Duty.php +37 -30
  15. app/code/local/Pb/Pbgsp/Model/Handlingoptions.php +17 -17
  16. app/code/local/Pb/Pbgsp/Model/Helper.php +18 -11
  17. app/code/local/Pb/Pbgsp/Model/Inboundparcel.php +17 -11
  18. app/code/local/Pb/Pbgsp/Model/Invoice/Duty.php +39 -31
  19. app/code/local/Pb/Pbgsp/Model/Messages.php +127 -121
  20. app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel.php +16 -9
  21. app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel/Collection.php +16 -8
  22. app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber.php +16 -9
  23. app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber/Collection.php +15 -8
  24. app/code/local/Pb/Pbgsp/Model/Mysql4/Variable.php +16 -9
  25. app/code/local/Pb/Pbgsp/Model/Mysql4/Variable/Collection.php +15 -8
  26. app/code/local/Pb/Pbgsp/Model/Observer.php +340 -318
  27. app/code/local/Pb/Pbgsp/Model/Ordernumber.php +17 -11
  28. app/code/local/Pb/Pbgsp/Model/Pdf/Tax.php +21 -14
  29. app/code/local/Pb/Pbgsp/Model/Quote/Duty.php +84 -76
  30. app/code/local/Pb/Pbgsp/Model/Resource/Mysql4/Setup.php +11 -10
  31. app/code/local/Pb/Pbgsp/Model/Sales/Order/Shipment.php +137 -136
  32. app/code/local/Pb/Pbgsp/Model/Util.php +29 -23
  33. app/code/local/Pb/Pbgsp/Model/Variable.php +17 -11
  34. app/code/local/Pb/Pbgsp/data/pb_pbgsp_setup/data-install-1.0.0.php +19 -0
  35. app/code/local/Pb/Pbgsp/etc/config.xml +509 -491
  36. app/code/local/Pb/Pbgsp/etc/system.xml +379 -361
  37. app/code/local/Pb/Pbgsp/sql/pbgsp_setup/mysql4-install-1.0.0.php +96 -60
  38. package.xml +5 -5
app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Invoice/Totals.php CHANGED
@@ -1,17 +1,25 @@
1
- <?php
2
- class Pb_Pbgsp_Block_Adminhtml_Sales_Order_Invoice_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals {
3
-
4
-
5
-
6
- public function addTotal(Varien_Object $total, $after=null) {
7
-
8
- $shipMethod = $this->getOrder()->getShippingMethod();
9
- $taxAmount = $this->getOrder()->getTaxAmount();
10
- $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
11
- return parent::addTotal($total,$after);
12
-
13
- }
14
-
15
- }
16
-
17
- ?>
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Invoice/Totals.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+ class Pb_Pbgsp_Block_Adminhtml_Sales_Order_Invoice_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals {
11
+
12
+
13
+
14
+ public function addTotal(Varien_Object $total, $after=null) {
15
+
16
+ $shipMethod = $this->getOrder()->getShippingMethod();
17
+ $taxAmount = $this->getOrder()->getTaxAmount();
18
+ $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
19
+ return parent::addTotal($total,$after);
20
+
21
+ }
22
+
23
+ }
24
+
25
+ ?>
app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Totals.php CHANGED
@@ -1,17 +1,26 @@
1
- <?php
2
- class Pb_Pbgsp_Block_Adminhtml_Sales_Order_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals {
3
-
4
-
5
-
6
- public function addTotal(Varien_Object $total, $after=null) {
7
-
8
- $shipMethod = $this->getOrder()->getShippingMethod();
9
- $taxAmount = $this->getOrder()->getTaxAmount();
10
- $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
11
- return parent::addTotal($total,$after);
12
-
13
- }
14
-
15
- }
16
-
17
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Block/Adminhtml/Sales/Order/Totals.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+
11
+ class Pb_Pbgsp_Block_Adminhtml_Sales_Order_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals {
12
+
13
+
14
+
15
+ public function addTotal(Varien_Object $total, $after=null) {
16
+
17
+ $shipMethod = $this->getOrder()->getShippingMethod();
18
+ $taxAmount = $this->getOrder()->getTaxAmount();
19
+ $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
20
+ return parent::addTotal($total,$after);
21
+
22
+ }
23
+
24
+ }
25
+
26
+ ?>
app/code/local/Pb/Pbgsp/Block/Checkout/Shipping/Method/Available.php CHANGED
@@ -1,67 +1,76 @@
1
- <?php
2
- class Pb_Pbgsp_Block_Checkout_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available {
3
-
4
- protected $errors;
5
- protected $restrictions;
6
-
7
- /**
8
- * Internal constructor, that is called from real constructor
9
- *
10
- */
11
- protected function _construct()
12
- {
13
- parent::_construct();
14
- $this->errors = Mage::getSingleton("customer/session")->getPbRestrictions();
15
- $cart = Mage::getModel('checkout/cart');
16
- $items = array();
17
- foreach($cart->getItems() as $item) {
18
- $items[$item->getProductId()] = array("name" => $item->getName(), "url" => $item->getProduct()->getProductUrl());
19
- }
20
-
21
- $this->restrictions = array();
22
- if(count($this->errors) > 0){
23
- foreach ($this->errors as $sku => $value) {
24
- $processor = new Pb_Pbgsp_Model_Messages();
25
- $message = $processor->getDisplayMessage($value["code"],$value["message"]);
26
-
27
- $product_sku = $this->getSku($value['index']);
28
- if($product_sku!=''):
29
- $i_sku = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku)->getName();
30
- $i_msg = "$i_sku needs to be removed or modified to continue.";
31
- $message = str_replace("{IDENTIFY SKU}", $i_msg, $message);
32
- else:
33
- $message = str_replace("{IDENTIFY SKU}", $product_sku, $message);
34
- endif;
35
- array_push($this->restrictions,array("name" => $items[$sku]["name"],
36
- "message" => $message,
37
- "sku" => $sku,
38
- "url" => $items[$sku]["url"]));
39
- }
40
- }
41
-
42
- }
43
-
44
- private function getSku($index){
45
- if($index == null) return '';
46
- $items = Mage::getSingleton('checkout/cart')->getItems();
47
- $i = 0;
48
- foreach ($items as $item):
49
- if($i++==$index):
50
- return $item->getSku();
51
- endif;
52
- endforeach;
53
- return '';
54
- }
55
- public function displayRestrictions() {
56
- if(isset($this->errors)) {
57
- return true;
58
- } else {
59
- return false;
60
- }
61
- }
62
-
63
- public function getRestrictions() {
64
- return $this->restrictions;
65
- }
66
- }
67
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Block/Checkout/Shipping/Method/Available.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+
11
+ class Pb_Pbgsp_Block_Checkout_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available {
12
+
13
+ protected $errors;
14
+ protected $restrictions;
15
+
16
+ /**
17
+ * Internal constructor, that is called from real constructor
18
+ *
19
+ */
20
+ protected function _construct()
21
+ {
22
+ parent::_construct();
23
+ $this->errors = Mage::getSingleton("customer/session")->getPbRestrictions();
24
+ $cart = Mage::getModel('checkout/cart');
25
+ $items = array();
26
+ foreach($cart->getItems() as $item) {
27
+ $items[$item->getProductId()] = array("name" => $item->getName(), "url" => $item->getProduct()->getProductUrl());
28
+ }
29
+
30
+ $this->restrictions = array();
31
+ if(count($this->errors) > 0){
32
+ foreach ($this->errors as $sku => $value) {
33
+ $processor = new Pb_Pbgsp_Model_Messages();
34
+ $message = $processor->getDisplayMessage($value["code"],$value["message"]);
35
+
36
+ $product_sku = $this->getSku($value['index']);
37
+ if($product_sku!=''):
38
+ $i_sku = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku)->getName();
39
+ $i_msg = "$i_sku needs to be removed or modified to continue.";
40
+ $message = str_replace("{IDENTIFY SKU}", $i_msg, $message);
41
+ else:
42
+ $message = str_replace("{IDENTIFY SKU}", $product_sku, $message);
43
+ endif;
44
+ array_push($this->restrictions,array("name" => $items[$sku]["name"],
45
+ "message" => $message,
46
+ "sku" => $sku,
47
+ "url" => $items[$sku]["url"]));
48
+ }
49
+ }
50
+
51
+ }
52
+
53
+ private function getSku($index){
54
+ if($index == null) return '';
55
+ $items = Mage::getSingleton('checkout/cart')->getItems();
56
+ $i = 0;
57
+ foreach ($items as $item):
58
+ if($i++==$index):
59
+ return $item->getSku();
60
+ endif;
61
+ endforeach;
62
+ return '';
63
+ }
64
+ public function displayRestrictions() {
65
+ if(isset($this->errors)) {
66
+ return true;
67
+ } else {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ public function getRestrictions() {
73
+ return $this->restrictions;
74
+ }
75
+ }
76
+ ?>
app/code/local/Pb/Pbgsp/Block/Form.php CHANGED
@@ -1,77 +1,60 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category Mage
22
- * @package Mage_Paypal
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
- /**
28
- * PayPal Standard payment "form"
29
- */
30
- class Pb_Pbgsp_Block_Form extends Mage_Payment_Block_Form
31
- {
32
- /**
33
- * Payment method code
34
- * @var string
35
- */
36
- protected $_methodCode = Mage_Paypal_Model_Config::METHOD_WPS;
37
-
38
- /**
39
- * Config model instance
40
- *
41
- * @var Mage_Paypal_Model_Config
42
- */
43
- protected $_config;
44
-
45
- /**
46
- * Set template and redirect message
47
- */
48
- protected function _construct()
49
- {
50
- Pb_Pbgsp_Model_Util::log("PBGSP form construct");
51
- $this->_config = Mage::getModel('paypal/config')->setMethod($this->getMethodCode());
52
- $locale = Mage::app()->getLocale();
53
- $mark = Mage::getConfig()->getBlockClassName('core/template');
54
- $mark = new $mark;
55
- $mark->setTemplate('paypal/payment/mark.phtml')
56
- ->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($locale))
57
- ->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($locale->getLocaleCode()))
58
- ; // known issue: code above will render only static mark image
59
- $this->setTemplate('paypal/payment/redirect.phtml')
60
- ->setRedirectMessage(
61
- Mage::helper('paypal')->__('You will be redirected to PayPal website when you place an order.')
62
- )
63
- ->setMethodTitle('') // Output PayPal mark, omit title
64
- ->setMethodLabelAfterHtml($mark->toHtml())
65
- ;
66
- return parent::_construct();
67
- }
68
-
69
- /**
70
- * Payment method code getter
71
- * @return string
72
- */
73
- public function getMethodCode()
74
- {
75
- return $this->_methodCode;
76
- }
77
- }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Block/Form.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ /**
11
+ * PayPal Standard payment "form"
12
+ */
13
+ class Pb_Pbgsp_Block_Form extends Mage_Payment_Block_Form
14
+ {
15
+ /**
16
+ * Payment method code
17
+ * @var string
18
+ */
19
+ protected $_methodCode = Mage_Paypal_Model_Config::METHOD_WPS;
20
+
21
+ /**
22
+ * Config model instance
23
+ *
24
+ * @var Mage_Paypal_Model_Config
25
+ */
26
+ protected $_config;
27
+
28
+ /**
29
+ * Set template and redirect message
30
+ */
31
+ protected function _construct()
32
+ {
33
+ Pb_Pbgsp_Model_Util::log("PBGSP form construct");
34
+ $this->_config = Mage::getModel('paypal/config')->setMethod($this->getMethodCode());
35
+ $locale = Mage::app()->getLocale();
36
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
37
+ $mark = new $mark;
38
+ $mark->setTemplate('paypal/payment/mark.phtml')
39
+ ->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($locale))
40
+ ->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($locale->getLocaleCode()))
41
+ ; // known issue: code above will render only static mark image
42
+ $this->setTemplate('paypal/payment/redirect.phtml')
43
+ ->setRedirectMessage(
44
+ Mage::helper('paypal')->__('You will be redirected to PayPal website when you place an order.')
45
+ )
46
+ ->setMethodTitle('') // Output PayPal mark, omit title
47
+ ->setMethodLabelAfterHtml($mark->toHtml())
48
+ ;
49
+ return parent::_construct();
50
+ }
51
+
52
+ /**
53
+ * Payment method code getter
54
+ * @return string
55
+ */
56
+ public function getMethodCode()
57
+ {
58
+ return $this->_methodCode;
59
+ }
60
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Pb/Pbgsp/Block/Sales/Order/Invoice/Totals.php CHANGED
@@ -1,14 +1,23 @@
1
- <?php
2
- class Pb_Pbgsp_Block_Sales_Order_Invoice_Totals extends Mage_Sales_Block_Order_Invoice_Totals {
3
-
4
- public function addTotal(Varien_Object $total, $after=null) {
5
-
6
- $shipMethod = $this->getOrder()->getShippingMethod();
7
- $taxAmount = $this->getOrder()->getTaxAmount();
8
- $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
9
- return parent::addTotal($total,$after);
10
-
11
- }
12
-
13
- }
14
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Block/Sales/Order/Invoice/Totals.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+
11
+ class Pb_Pbgsp_Block_Sales_Order_Invoice_Totals extends Mage_Sales_Block_Order_Invoice_Totals {
12
+
13
+ public function addTotal(Varien_Object $total, $after=null) {
14
+
15
+ $shipMethod = $this->getOrder()->getShippingMethod();
16
+ $taxAmount = $this->getOrder()->getTaxAmount();
17
+ $total = Pb_Pbgsp_Block_Sales_Order_Totals::addDuties($total,$after,$shipMethod,$taxAmount);
18
+ return parent::addTotal($total,$after);
19
+
20
+ }
21
+
22
+ }
23
+ ?>
app/code/local/Pb/Pbgsp/Block/Sales/Order/Totals.php CHANGED
@@ -1,35 +1,56 @@
1
- <?php
2
- class Pb_Pbgsp_Block_Sales_Order_Totals extends Mage_Sales_Block_Order_Totals {
3
-
4
- public static function addDuties(Varien_Object $total, $after, $shipMethod, $taxAmount) {
5
-
6
- // TODO: This is kind of ugly. I am replacing the tax template with a tax entry...
7
- // By default this sets the block_name without parameters which loads the appropriate
8
- // template. Need to see if this breaks anything.
9
-
10
- $len = strlen("pbgsp_");
11
- if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
12
- if ($total->getCode() == "tax") {
13
- $total = new Varien_Object(array(
14
- 'code' => 'tax',
15
- 'value' => $taxAmount,
16
- 'label' => 'Duty & Taxes'
17
- ));
18
- }
19
- }
20
-
21
- return $total;
22
- }
23
-
24
- public function addTotal(Varien_Object $total, $after=null) {
25
-
26
- $shipMethod = $this->getOrder()->getShippingMethod();
27
- $taxAmount = $this->getOrder()->getTaxAmount();
28
- Pb_Pbgsp_Model_Util::log("Add Duty & Taxes at Order");
29
- $total = self::addDuties($total,$after,$shipMethod,$taxAmount);
30
- return parent::addTotal($total,$after);
31
-
32
- }
33
-
34
- }
35
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Block/Sales/Order/Totals.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Block_Sales_Order_Totals extends Mage_Sales_Block_Order_Totals {
10
+
11
+ public static function addDuties(Varien_Object $total, $after, $shipMethod, $taxAmount) {
12
+
13
+ // TODO: This is kind of ugly. I am replacing the tax template with a tax entry...
14
+ // By default this sets the block_name without parameters which loads the appropriate
15
+ // template. Need to see if this breaks anything.
16
+
17
+ $len = strlen("pbgsp_");
18
+ if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
19
+ if ($total->getCode() == "tax") {
20
+ $total = new Varien_Object(array(
21
+ 'code' => 'tax',
22
+ 'value' => $taxAmount,
23
+ 'label' => 'Importation Charges'
24
+ ));
25
+ }
26
+ }
27
+
28
+ return $total;
29
+ }
30
+
31
+ public function addTotal(Varien_Object $total, $after=null) {
32
+
33
+ $shipMethod = $this->getOrder()->getShippingMethod();
34
+ $taxAmount = $this->getOrder()->getTaxAmount();
35
+ Pb_Pbgsp_Model_Util::log("Add Duty & Taxes at Order");
36
+ $total = self::addDuties($total,$after,$shipMethod,$taxAmount);
37
+ return parent::addTotal($total,$after);
38
+
39
+ }
40
+ public function getTotals($area=null)
41
+ {
42
+ $totals = parent::getTotals($area);
43
+ $shipMethod = $this->getOrder()->getShippingMethod();
44
+ $len = strlen("pbgsp_");
45
+ if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
46
+ Pb_Pbgsp_Model_Util::log("getTotals PB shipmethod");
47
+ if(array_key_exists("shipping",$totals)) {
48
+ $shipping = $totals['shipping'];
49
+ $shipping->setLabel('Transportation Charges');
50
+ }
51
+ }
52
+
53
+ return $totals;
54
+ }
55
+ }
56
+ ?>
app/code/local/Pb/Pbgsp/Model/Api.php CHANGED
@@ -1,443 +1,452 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Api
3
- {
4
-
5
-
6
- public static function CallAPI($method, $url, $data = false,$isSecondCall=false)
7
- {
8
- $curl = curl_init();
9
- $headers = array();
10
- $dataString = '';
11
- switch ($method)
12
- {
13
- case "POST":
14
- curl_setopt($curl, CURLOPT_POST, 1);
15
-
16
- if ($data) {
17
- $dataString = json_encode($data);
18
- Pb_Pbgsp_Model_Util::log("Data to pass to get quote $dataString");
19
- $headers[] = 'Content-Type: application/json';
20
- $headers[] = 'Content-Length: ' . strlen($dataString);
21
- curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
22
- }
23
-
24
- break;
25
- case "PUT":
26
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
27
- if ($data) {
28
- $dataString = json_encode($data);
29
- Pb_Pbgsp_Model_Util::log("Data to pass to PUT $dataString");
30
- $headers[] = 'Content-Type: application/json';
31
- $headers[] = 'Content-Length: ' . strlen($dataString);
32
- curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
33
- }
34
- break;
35
- default:
36
- if ($data)
37
- $url = sprintf("%s?%s", $url, http_build_query($data));
38
- }
39
- if($dataString != '')
40
- Pb_Pbgsp_Model_Util::log("Passing $dataString to $url");
41
- curl_setopt($curl, CURLOPT_URL, $url);
42
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
43
- $token = self::getToken();
44
- if(!$token)
45
- throw new Exception("Could not get authentication token");
46
- $headers[] = 'Cookie: '. $token['cookie'][0];
47
- $headers[] = 'Authorization: '.$token['token_type'].' '.$token['access_token'];
48
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers );
49
- curl_setopt($curl, CURLOPT_VERBOSE, 1); // turn verbose on
50
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
51
- $result = curl_exec($curl);
52
- $info = curl_getinfo($curl);
53
- //Pb_Pbgsp_Model_Util::log($info);
54
- $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
55
- if($status != 200 && $status != 201 && $status != 400)
56
- {
57
- Pb_Pbgsp_Model_Util::log("Http Status: $status");
58
- Pb_Pbgsp_Model_Util::log("body : $result");
59
- if($status == 401 && !$isSecondCall) {
60
- //token expired regenerat it
61
- Pb_Pbgsp_Model_Util::log("Regenerating token");
62
- Mage::getSingleton("customer/session")->setPbToken(false);
63
- self::CallAPI($method,$url,$data,true);
64
- }
65
- else {
66
- throw new Exception($result,$status);
67
- }
68
- }
69
- curl_close($curl);
70
- return $result;
71
- }
72
-
73
- public static function getToken() {
74
- $token = Mage::getSingleton("customer/session")->getPbToken();
75
- if(!$token) {
76
- $curl = curl_init();
77
- curl_setopt($curl, CURLOPT_POST, 1);
78
- $username = trim(Pb_Pbgsp_Model_Credentials::getUsername());
79
- $password = trim(Pb_Pbgsp_Model_Credentials::getPassword());
80
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
81
- curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
82
- curl_setopt($curl, CURLINFO_HEADER_OUT, 1); // capture the header info
83
- curl_setopt($curl, CURLOPT_VERBOSE, 1); // turn verbose on
84
- // get headers too with this line
85
- curl_setopt($curl, CURLOPT_HEADER, 1);
86
- curl_setopt($curl, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
87
- // Will return the response, if false it print the response
88
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
89
- $url = Pb_Pbgsp_Model_Credentials::getApiUrl().'/auth/token';
90
- curl_setopt($curl, CURLOPT_URL, $url);
91
- $response = curl_exec($curl);
92
- $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
93
- $header = substr($response, 0, $header_size);
94
- // get cookies
95
- $cookies = array();
96
- preg_match_all('/Set-Cookie:(?<cookie>\s{0,}.*)$/im', $header, $cookies);
97
- $body = substr($response, $header_size);
98
- $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
99
- $info = curl_getinfo($curl);
100
- if($status != 200) {
101
- throw new Exception("Could not get authentication token",$status);
102
- }
103
- curl_close($curl);
104
- $token = json_decode($body,true);
105
- $token['cookie'] = $cookies['cookie'];
106
- Mage::getSingleton("customer/session")->setPbToken($token);
107
- }
108
- return $token;
109
- }
110
-
111
- protected static function getClientIP() {
112
- $ipaddress = '';
113
- if (array_key_exists('HTTP_CLIENT_IP',$_SERVER))
114
- $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
115
- else if (array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER))
116
- $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
117
- else if (array_key_exists('HTTP_X_FORWARDED',$_SERVER))
118
- $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
119
- else if (array_key_exists('HTTP_FORWARDED_FOR',$_SERVER))
120
- $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
121
- else if (array_key_exists('HTTP_FORWARDED',$_SERVER))
122
- $ipaddress = $_SERVER['HTTP_FORWARDED'];
123
- else if (array_key_exists('REMOTE_ADDR',$_SERVER))
124
- $ipaddress = $_SERVER['REMOTE_ADDR'];
125
- else
126
- $ipaddress = '0.0.0.0';
127
- return $ipaddress;
128
- }
129
- protected static function makeBasket($products, $address,$method='STANDARD')
130
- {
131
- $basketLines = array();
132
- $totalProducts = 0;
133
- /* BigPixel code for adding handling fee, 6/6/2012*/
134
-
135
-
136
- $handlingFee = Pb_Pbgsp_Model_Credentials::getHandlingFee();
137
-
138
- $handlingoption = Pb_Pbgsp_Model_Credentials::getHandlingOption();
139
- $domesticShippingFee = Pb_Pbgsp_Model_Credentials::getDomesticShippingFee();
140
- $domesticShippingOption = Pb_Pbgsp_Model_Credentials::getDomesticShippingOption();
141
-
142
- $deliveryAdjMinDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMinDays();
143
- $deliveryAdjMixDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMaxDays();
144
-
145
- foreach ($products as $product) {
146
- if ((!$product->getParentItem() && $product->getRealProductType()
147
- != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) ||
148
- ($product->getParentItem() && $product->isChildrenCalculated())) {
149
- /* @var Mage_Sales_Model_Order_Item $product */
150
-
151
- $totalProducts += $product->getQty();
152
- //$value = $product->getPrice() - ($product->getDiscountAmount() / $product->getQty());
153
- /* @var Mage_Catalog_Model_Product $realProd*/
154
- //$realProd = $product->getProduct();
155
- //Pb_Pbgsp_Model_Util::log('discount amount'. $product->getDiscountAmount());
156
- //$price = $realProd->getPrice();
157
- $price = $product->getPrice();//$price - ($product->getDiscountAmount() * $product->getQty());
158
- array_push($basketLines, array(
159
- "lineId" => $product->getSku(),
160
- "commodity" => array('merchantComRefId' => $product->getSku()),
161
- "unitPrice" => array('price' => array('value' => $price)),
162
- "quantity" => intval($product->getQty())
163
-
164
- )
165
- );
166
- }
167
-
168
- }
169
-
170
- if(isset($handlingoption) && $handlingoption == "2") { //apply as per item
171
- $handlingFee = $handlingFee * $totalProducts;
172
- }
173
- if(isset($domesticShippingOption) && $domesticShippingOption == "2") { //apply as per item
174
- $domesticShippingFee = $domesticShippingFee * $totalProducts;
175
- }
176
- $toHubTransportations = array(
177
- array(
178
- 'merchantShippingIdentifier' => 'PB',
179
- 'speed' => $method,
180
- 'shipping' => array('value' => $handlingFee),
181
- 'handling' => array('value' => $domesticShippingFee),
182
- 'total' => array('value' => $handlingFee + $domesticShippingFee),
183
- 'minDays' => $deliveryAdjMinDays,
184
- 'maxDays' => $deliveryAdjMixDays
185
- )
186
- );
187
-
188
- if (strlen($address->getEmail()) > 0) {
189
- $email = $address->getEmail();
190
- }
191
- elseif (strlen(Mage::getSingleton('checkout/cart')->getQuote()->getBillingAddress()->getEmail()) > 0) {
192
- $email = Mage::getSingleton('checkout/cart')->getQuote()->getBillingAddress()->getEmail();
193
- }
194
- else {
195
- $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
196
- }
197
- if(!$email)
198
- $email = "kamranattari@gmail.com";
199
-
200
- $consignee = array(
201
- 'familyName' => $address->getLastname(),
202
- 'givenName' => $address->getFirstname(),
203
- 'email' => $email,
204
- 'phoneNumbers' => array(
205
- array(
206
- 'number' => $address->getTelephone(),
207
- 'type' => 'other'
208
- )
209
- )
210
- );
211
- $shippingAddress = array(
212
- 'street1' => $address->getStreet1(),
213
- 'street2' => $address->getStreet2(),
214
-
215
- 'city' => $address->getCity(),
216
- 'countyOrRegion' => '',
217
- 'provinceOrState' => $address->getRegionCode(),
218
- 'country' => $address->getCountryId(),
219
- 'postalOrZipCode' => $address->getPostcode()
220
- );
221
- $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
222
- $basket = array(
223
- 'merchantId' => Pb_Pbgsp_Model_Credentials::getMerchantCode(),
224
- 'purchaserIPAddress' => self::getClientIP(),
225
- 'transactionId' => mt_rand(100000, 999999),
226
- 'quoteCurrency' => $currency,
227
- 'basketLines' => $basketLines
228
- ,
229
- 'toHubTransportations' => $toHubTransportations,
230
- 'consignee' => $consignee
231
- ,
232
- 'shippingAddress' => $shippingAddress
233
-
234
- );
235
-
236
-
237
- return $basket;
238
-
239
- }
240
-
241
- public static function generateInboundParcelNumber($shipment,$items,$mageOrderNumber,$cpOrderNumber) {
242
- $inboundParcelCommodities = array();
243
- /* @var Mage_Sales_Model_Order_Shipment $shipment*/
244
- $totalWeight = 0;
245
- foreach($shipment->getItemsCollection() as $item) {
246
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku());
247
- $commodity = array(
248
- 'merchantComRefId' => $item->getSku(),
249
-
250
- 'quantity' => intval($item->getQty()),
251
- 'coo' => $product->getCountryOfManufacture(),
252
- 'size' => array(
253
- 'weight' => $product->getWeight(),
254
- 'weightUnit' => 'lb'
255
- )
256
-
257
- );
258
- array_push($inboundParcelCommodities,$commodity);
259
- $totalWeight += $product->getWeight();
260
- }
261
- $tracks = array();
262
-
263
- foreach($shipment->getTracksCollection() as $track) {
264
- $tracks[] = $track;
265
- }
266
- $requestBody = array(
267
- 'merchantOrderNumber' => $cpOrderNumber,
268
- 'parcelIdentificationNumber' => $tracks[0]->getNumber(),
269
- 'inboundParcelCommodities' => $inboundParcelCommodities,
270
- 'shipper' => $tracks[0]->getTitle(),
271
- 'shipperService' => 'EXPRESS',
272
- 'shipperTrackingNumber'=> $tracks[0]->getNumber(),
273
- 'dcId' => '211113442',
274
- 'dcAddress' => array(
275
- 'street1' => '200 Main Street',
276
- 'city' => 'PHOENIX',
277
- 'provinceOrState' => 'AZ',
278
- 'country' => 'US',
279
- 'postalOrZipCode' => '85123'
280
- ),
281
- 'returnDetails' => array(
282
- 'returnAddress' => array(
283
- 'street1' => '200 Main Street',
284
- 'city' => 'PHOENIX',
285
- 'provinceOrState' => 'AZ',
286
- 'country' => 'US',
287
- 'postalOrZipCode' => '85123'
288
- ),
289
- 'contactInformation' => array(
290
- 'familyName' => 'Smith',
291
- 'givenName' => 'Mary',
292
- 'email' => 'retailer_email@test.com',
293
- 'phoneNumbers' => array(
294
- array(
295
- 'number' => '12123232',
296
- 'type' => 'home'
297
- )
298
- )
299
- )
300
- ),
301
- 'size' => array(
302
- 'weight' => $totalWeight,
303
- 'weightUnit' => 'LB'
304
- )
305
- );
306
- $url = Pb_Pbgsp_Model_Credentials::getOrderMgmtAPIUrl().'/orders/'.
307
- $cpOrderNumber.'/inbound-parcels';
308
- $response = self::CallAPI('POST',$url,$requestBody);
309
- $parcelResponse = json_decode($response,true);
310
- Pb_Pbgsp_Model_Util::log('Response of inbound-parcels');
311
- Pb_Pbgsp_Model_Util::log($parcelResponse);
312
- return $parcelResponse;
313
-
314
- }
315
- public static function getCheckoutUrl($method) {
316
- return Pb_Pbgsp_Model_Credentials::getApiUrl().'/checkout/services/v1/'.$method;
317
- }
318
- public static function getQuote($products,$address)
319
- {
320
-
321
- Pb_Pbgsp_Model_Util::log('Getting quote from clearpath');
322
- $basket = Pb_Pbgsp_Model_Api::makeBasket($products, $address);
323
-
324
- $url = self::getCheckoutUrl('quotes');
325
- $response = self::CallAPI('POST',$url,$basket);
326
-
327
-
328
- $quoteSet = json_decode($response,true);
329
- Pb_Pbgsp_Model_Util::log('response of quotes ');
330
- Pb_Pbgsp_Model_Util::log($quoteSet);
331
- return $quoteSet;
332
-
333
-
334
- }
335
-
336
-
337
- public static function createOrder($products,$method,$address) {
338
-
339
-
340
- try {
341
- Pb_Pbgsp_Model_Util::log('Creating order in clearpath');
342
- $basket = Pb_Pbgsp_Model_Api::makeBasket($products, $address,$method);
343
-
344
- $url = self::getCheckoutUrl('orders');
345
- $response = self::CallAPI('POST',$url,$basket);
346
-
347
-
348
- $orderSet = json_decode($response,true);
349
- Pb_Pbgsp_Model_Util::log('response of orders ');
350
- Pb_Pbgsp_Model_Util::log($orderSet);
351
- foreach($orderSet['order'] as $order) {
352
- $tax = 0;
353
- if(!self::logIfError($order,'createOrder')) {
354
- // if(array_key_exists('order',$order)) {
355
- // $quote = $order['order'];
356
- // $tax = $quote['totalImportation']['total']['value'];
357
- // }
358
-
359
- return $order;//array("orderNumber" => $order['orderId'], "tax" => $tax);
360
- }
361
- else {
362
- return false;
363
- }
364
-
365
- }
366
- return $orderSet;
367
- }
368
- catch(Exception $e) {
369
- Pb_Pbgsp_Model_Util::log("Received unexpected exception from Pb while calling createOrder.");
370
- Pb_Pbgsp_Model_Util::logException($e);
371
-
372
-
373
- }
374
-
375
- }
376
-
377
- private static function logIfError($object,$action=null) {
378
- if(array_key_exists('errors',$object) && count($object['errors']) > 0) {
379
- $processor = new Pb_Pbgsp_Model_Messages();
380
- foreach($object['errors'] as $error) {
381
- $message = '';
382
- if(array_key_exists('message',$error))
383
- $message = $error['message'];
384
- $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
385
- if($action)
386
- Pb_Pbgsp_Model_Util::log("Error received in action $action");
387
- Pb_Pbgsp_Model_Util::log($message);
388
- }
389
- return true;
390
- }
391
- return false;
392
- }
393
- public static function confirmOrder($orderNumber,$order) {
394
- /* @var Mage_Sales_Model_Order $order */
395
-
396
-
397
-
398
- $billingAddress = $order->getBillingAddress();
399
- $confirm = array(
400
- 'transactionId' => $order->getRealOrderId(),
401
- 'merchantOrderNumber' => $order->getRealOrderId(),
402
- 'purchaser' => array(
403
- 'familyName' => $order->getCustomerLastname(),
404
- 'givenName' => $order->getCustomerFirstname(),
405
- 'email' => $order->getCustomerEmail(),
406
- 'phoneNumbers' => array(
407
- array(
408
- 'number' => $billingAddress->getTelephone(),
409
- 'type' => 'other'
410
- )
411
- )),
412
- 'purchaserBillingAddress' => array(
413
- 'street1' => $billingAddress->getStreet1(),
414
- 'street2' => '',
415
- 'city' => $billingAddress->getCity(),
416
- 'countyOrRegion' => '',
417
- 'provinceOrState' => $billingAddress->getRegionCode(),
418
- 'country' => $billingAddress->getCountryId(),
419
- 'postalOrZipCode' => $billingAddress->getPostcode(),
420
- )
421
-
422
- );
423
- try {
424
- $url = self::getCheckoutUrl("orders/$orderNumber/confirm");
425
- $response = self::CallAPI('PUT',$url,$confirm);
426
- Pb_Pbgsp_Model_Util::log("Passing $url ");
427
- Pb_Pbgsp_Model_Util::log($confirm);
428
- $confirmResponse = json_decode($response,true);
429
- if(self::logIfError($confirmResponse,'confirmOrder'))//there is an error
430
- return false;
431
- return true;
432
- }
433
- catch(Exception $e) {
434
- Pb_Pbgsp_Model_Util::log("Received unexpected exception from Pb while calling confirming order.");
435
- Pb_Pbgsp_Model_Util::log($e->getMessage(). ' '. $e->getTraceAsString());
436
- return false;
437
- }
438
- return true;
439
- }
440
-
441
- }
442
-
443
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Api.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Api
10
+ {
11
+
12
+
13
+ public static function CallAPI($method, $url, $data = false,$isSecondCall=false)
14
+ {
15
+ $curl = curl_init();
16
+ $headers = array();
17
+ $dataString = '';
18
+ switch ($method)
19
+ {
20
+ case "POST":
21
+ curl_setopt($curl, CURLOPT_POST, 1);
22
+
23
+ if ($data) {
24
+ $dataString = json_encode($data);
25
+ Pb_Pbgsp_Model_Util::log("Data to pass to get quote $dataString");
26
+ $headers[] = 'Content-Type: application/json';
27
+ $headers[] = 'Content-Length: ' . strlen($dataString);
28
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
29
+ }
30
+
31
+ break;
32
+ case "PUT":
33
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
34
+ if ($data) {
35
+ $dataString = json_encode($data);
36
+ Pb_Pbgsp_Model_Util::log("Data to pass to PUT $dataString");
37
+ $headers[] = 'Content-Type: application/json';
38
+ $headers[] = 'Content-Length: ' . strlen($dataString);
39
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
40
+ }
41
+ break;
42
+ default:
43
+ if ($data)
44
+ $url = sprintf("%s?%s", $url, http_build_query($data));
45
+ }
46
+ if($dataString != '')
47
+ Pb_Pbgsp_Model_Util::log("Passing $dataString to $url");
48
+ curl_setopt($curl, CURLOPT_URL, $url);
49
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
50
+ $token = self::getToken();
51
+ if(!$token)
52
+ throw new Exception("Could not get authentication token");
53
+ $headers[] = 'Cookie: '. $token['cookie'][0];
54
+ $headers[] = 'Authorization: '.$token['token_type'].' '.$token['access_token'];
55
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers );
56
+ curl_setopt($curl, CURLOPT_VERBOSE, 1); // turn verbose on
57
+ curl_setopt($curl, CURLINFO_HEADER_OUT, true);
58
+ $result = curl_exec($curl);
59
+ $info = curl_getinfo($curl);
60
+ //Pb_Pbgsp_Model_Util::log($info);
61
+ $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
62
+ if($status != 200 && $status != 201 && $status != 400)
63
+ {
64
+ Pb_Pbgsp_Model_Util::log("Http Status: $status");
65
+ Pb_Pbgsp_Model_Util::log("body : $result");
66
+ if($status == 401 && !$isSecondCall) {
67
+ //token expired regenerat it
68
+ Pb_Pbgsp_Model_Util::log("Regenerating token");
69
+ Mage::getSingleton("customer/session")->setPbToken(false);
70
+ self::CallAPI($method,$url,$data,true);
71
+ }
72
+ else {
73
+ throw new Exception($result,$status);
74
+ }
75
+ }
76
+ curl_close($curl);
77
+ return $result;
78
+ }
79
+
80
+ public static function getToken() {
81
+ $token = Mage::getSingleton("customer/session")->getPbToken();
82
+ if(!$token) {
83
+ $curl = curl_init();
84
+ curl_setopt($curl, CURLOPT_POST, 1);
85
+ $username = trim(Pb_Pbgsp_Model_Credentials::getUsername());
86
+ $password = trim(Pb_Pbgsp_Model_Credentials::getPassword());
87
+ curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
88
+ curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
89
+ curl_setopt($curl, CURLINFO_HEADER_OUT, 1); // capture the header info
90
+ curl_setopt($curl, CURLOPT_VERBOSE, 1); // turn verbose on
91
+ // get headers too with this line
92
+ curl_setopt($curl, CURLOPT_HEADER, 1);
93
+ curl_setopt($curl, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
94
+ // Will return the response, if false it print the response
95
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
96
+ $url = Pb_Pbgsp_Model_Credentials::getAuthorizationUrl();
97
+ curl_setopt($curl, CURLOPT_URL, $url);
98
+ $response = curl_exec($curl);
99
+ $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
100
+ $header = substr($response, 0, $header_size);
101
+ // get cookies
102
+ $cookies = array();
103
+ preg_match_all('/Set-Cookie:(?<cookie>\s{0,}.*)$/im', $header, $cookies);
104
+ $body = substr($response, $header_size);
105
+ $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
106
+ $info = curl_getinfo($curl);
107
+ if($status != 200) {
108
+ Pb_Pbgsp_Model_Util::log("Error getting authentication token.". $response);
109
+ throw new Exception("Could not get authentication token",$status);
110
+ }
111
+ curl_close($curl);
112
+ $token = json_decode($body,true);
113
+ $token['cookie'] = $cookies['cookie'];
114
+ Mage::getSingleton("customer/session")->setPbToken($token);
115
+ }
116
+ return $token;
117
+ }
118
+
119
+ protected static function getClientIP() {
120
+ $ipaddress = '';
121
+ if (array_key_exists('HTTP_CLIENT_IP',$_SERVER))
122
+ $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
123
+ else if (array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER))
124
+ $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
125
+ else if (array_key_exists('HTTP_X_FORWARDED',$_SERVER))
126
+ $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
127
+ else if (array_key_exists('HTTP_FORWARDED_FOR',$_SERVER))
128
+ $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
129
+ else if (array_key_exists('HTTP_FORWARDED',$_SERVER))
130
+ $ipaddress = $_SERVER['HTTP_FORWARDED'];
131
+ else if (array_key_exists('REMOTE_ADDR',$_SERVER))
132
+ $ipaddress = $_SERVER['REMOTE_ADDR'];
133
+ else
134
+ $ipaddress = '0.0.0.0';
135
+ return $ipaddress;
136
+ }
137
+ protected static function makeBasket($products, $address,$method='STANDARD')
138
+ {
139
+ $basketLines = array();
140
+ $totalProducts = 0;
141
+ /* BigPixel code for adding handling fee, 6/6/2012*/
142
+
143
+
144
+ $handlingFee = Pb_Pbgsp_Model_Credentials::getHandlingFee();
145
+
146
+ $handlingoption = Pb_Pbgsp_Model_Credentials::getHandlingOption();
147
+ $domesticShippingFee = Pb_Pbgsp_Model_Credentials::getDomesticShippingFee();
148
+ $domesticShippingOption = Pb_Pbgsp_Model_Credentials::getDomesticShippingOption();
149
+
150
+ $deliveryAdjMinDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMinDays();
151
+ $deliveryAdjMixDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMaxDays();
152
+
153
+ foreach ($products as $product) {
154
+ if ((!$product->getParentItem() && $product->getRealProductType()
155
+ != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) ||
156
+ ($product->getParentItem() && $product->isChildrenCalculated())) {
157
+ /* @var Mage_Sales_Model_Order_Item $product */
158
+
159
+ $totalProducts += $product->getQty();
160
+
161
+ // Pb_Pbgsp_Model_Util::log('discount amount '. $product->getDiscountAmount());
162
+ // Pb_Pbgsp_Model_Util::log('Price '. $product->getPrice());
163
+
164
+ $price = $product->getPrice() - $product->getDiscountAmount();//$price - ($product->getDiscountAmount() * $product->getQty());
165
+ if($price == 0)
166
+ $price = 0.01; //set this price so that quote could be retrieved.
167
+ array_push($basketLines, array(
168
+ "lineId" => $product->getSku(),
169
+ "commodity" => array('merchantComRefId' => $product->getSku()),
170
+ "unitPrice" => array('price' => array('value' => $price)),
171
+ "quantity" => intval($product->getQty())
172
+
173
+ )
174
+ );
175
+ }
176
+
177
+ }
178
+
179
+ if(isset($handlingoption) && $handlingoption == "2") { //apply as per item
180
+ $handlingFee = $handlingFee * $totalProducts;
181
+ }
182
+ if(isset($domesticShippingOption) && $domesticShippingOption == "2") { //apply as per item
183
+ $domesticShippingFee = $domesticShippingFee * $totalProducts;
184
+ }
185
+ $toHubTransportations = array(
186
+ array(
187
+ 'merchantShippingIdentifier' => 'PB',
188
+ 'speed' => $method,
189
+ 'shipping' => array('value' => $handlingFee),
190
+ 'handling' => array('value' => $domesticShippingFee),
191
+ 'total' => array('value' => $handlingFee + $domesticShippingFee),
192
+ 'minDays' => $deliveryAdjMinDays,
193
+ 'maxDays' => $deliveryAdjMixDays
194
+ )
195
+ );
196
+
197
+ if (strlen($address->getEmail()) > 0) {
198
+ $email = $address->getEmail();
199
+ }
200
+ elseif (strlen(Mage::getSingleton('checkout/cart')->getQuote()->getBillingAddress()->getEmail()) > 0) {
201
+ $email = Mage::getSingleton('checkout/cart')->getQuote()->getBillingAddress()->getEmail();
202
+ }
203
+ else {
204
+ $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
205
+ }
206
+ if(!$email)
207
+ $email = "kamranattari@gmail.com";
208
+
209
+ $consignee = array(
210
+ 'familyName' => $address->getLastname(),
211
+ 'givenName' => $address->getFirstname(),
212
+ 'email' => $email,
213
+ 'phoneNumbers' => array(
214
+ array(
215
+ 'number' => $address->getTelephone(),
216
+ 'type' => 'other'
217
+ )
218
+ )
219
+ );
220
+ $shippingAddress = array(
221
+ 'street1' => $address->getStreet1(),
222
+ 'street2' => $address->getStreet2(),
223
+
224
+ 'city' => $address->getCity(),
225
+ 'countyOrRegion' => '',
226
+ 'provinceOrState' => $address->getRegionCode(),
227
+ 'country' => $address->getCountryId(),
228
+ 'postalOrZipCode' => $address->getPostcode()
229
+ );
230
+ $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
231
+ $basket = array(
232
+ 'merchantId' => Pb_Pbgsp_Model_Credentials::getMerchantCode(),
233
+ 'purchaserIPAddress' => self::getClientIP(),
234
+ 'transactionId' => mt_rand(100000, 999999),
235
+ 'quoteCurrency' => $currency,
236
+ 'basketLines' => $basketLines
237
+ ,
238
+ 'toHubTransportations' => $toHubTransportations,
239
+ 'consignee' => $consignee
240
+ ,
241
+ 'shippingAddress' => $shippingAddress
242
+
243
+ );
244
+
245
+
246
+ return $basket;
247
+
248
+ }
249
+
250
+ public static function generateInboundParcelNumber($shipment,$items,$mageOrderNumber,$cpOrderNumber) {
251
+ $inboundParcelCommodities = array();
252
+ /* @var Mage_Sales_Model_Order_Shipment $shipment*/
253
+ $totalWeight = 0;
254
+ foreach($shipment->getItemsCollection() as $item) {
255
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku());
256
+ $commodity = array(
257
+ 'merchantComRefId' => $item->getSku(),
258
+
259
+ 'quantity' => intval($item->getQty()),
260
+ 'coo' => $product->getCountryOfManufacture(),
261
+ 'size' => array(
262
+ 'weight' => $product->getWeight(),
263
+ 'weightUnit' => 'lb'
264
+ )
265
+
266
+ );
267
+ array_push($inboundParcelCommodities,$commodity);
268
+ $totalWeight += $product->getWeight();
269
+ }
270
+ $tracks = array();
271
+
272
+ foreach($shipment->getTracksCollection() as $track) {
273
+ $tracks[] = $track;
274
+ }
275
+ $requestBody = array(
276
+ 'merchantOrderNumber' => $cpOrderNumber,
277
+ 'parcelIdentificationNumber' => $tracks[0]->getNumber(),
278
+ 'inboundParcelCommodities' => $inboundParcelCommodities,
279
+ 'shipper' => $tracks[0]->getTitle(),
280
+ 'shipperService' => 'EXPRESS',
281
+ 'shipperTrackingNumber'=> $tracks[0]->getNumber(),
282
+ 'dcId' => '211113442',
283
+ 'dcAddress' => array(
284
+ 'street1' => '200 Main Street',
285
+ 'city' => 'PHOENIX',
286
+ 'provinceOrState' => 'AZ',
287
+ 'country' => 'US',
288
+ 'postalOrZipCode' => '85123'
289
+ ),
290
+ 'returnDetails' => array(
291
+ 'returnAddress' => array(
292
+ 'street1' => '200 Main Street',
293
+ 'city' => 'PHOENIX',
294
+ 'provinceOrState' => 'AZ',
295
+ 'country' => 'US',
296
+ 'postalOrZipCode' => '85123'
297
+ ),
298
+ 'contactInformation' => array(
299
+ 'familyName' => 'Smith',
300
+ 'givenName' => 'Mary',
301
+ 'email' => 'retailer_email@test.com',
302
+ 'phoneNumbers' => array(
303
+ array(
304
+ 'number' => '12123232',
305
+ 'type' => 'home'
306
+ )
307
+ )
308
+ )
309
+ ),
310
+ 'size' => array(
311
+ 'weight' => $totalWeight,
312
+ 'weightUnit' => 'LB'
313
+ )
314
+ );
315
+ $url = Pb_Pbgsp_Model_Credentials::getOrderMgmtAPIUrl().'/orders/'.
316
+ $cpOrderNumber.'/inbound-parcels';
317
+ $response = self::CallAPI('POST',$url,$requestBody);
318
+ $parcelResponse = json_decode($response,true);
319
+ Pb_Pbgsp_Model_Util::log('Response of inbound-parcels');
320
+ Pb_Pbgsp_Model_Util::log($parcelResponse);
321
+ return $parcelResponse;
322
+
323
+ }
324
+ public static function getCheckoutUrl($method) {
325
+ return Pb_Pbgsp_Model_Credentials::getCheckoutUrl().'/'.$method;
326
+ }
327
+ public static function getQuote($products,$address)
328
+ {
329
+
330
+ Pb_Pbgsp_Model_Util::log('Getting quote from clearpath');
331
+ $basket = Pb_Pbgsp_Model_Api::makeBasket($products, $address);
332
+
333
+ $url = self::getCheckoutUrl('quotes');
334
+ $response = self::CallAPI('POST',$url,$basket);
335
+
336
+
337
+ $quoteSet = json_decode($response,true);
338
+ Pb_Pbgsp_Model_Util::log('response of quotes ');
339
+ Pb_Pbgsp_Model_Util::log($quoteSet);
340
+ return $quoteSet;
341
+
342
+
343
+ }
344
+
345
+
346
+ public static function createOrder($products,$method,$address) {
347
+
348
+
349
+ try {
350
+ Pb_Pbgsp_Model_Util::log('Creating order in clearpath');
351
+ $basket = Pb_Pbgsp_Model_Api::makeBasket($products, $address,$method);
352
+
353
+ $url = self::getCheckoutUrl('orders');
354
+ $response = self::CallAPI('POST',$url,$basket);
355
+ Pb_Pbgsp_Model_Util::log("response of create order ". $response );
356
+
357
+ $orderSet = json_decode($response,true);
358
+ Pb_Pbgsp_Model_Util::log('response of orders ');
359
+ Pb_Pbgsp_Model_Util::log($orderSet);
360
+ foreach($orderSet['order'] as $order) {
361
+ $tax = 0;
362
+ if(!self::logIfError($order,'createOrder')) {
363
+ // if(array_key_exists('order',$order)) {
364
+ // $quote = $order['order'];
365
+ // $tax = $quote['totalImportation']['total']['value'];
366
+ // }
367
+
368
+ return $order;//array("orderNumber" => $order['orderId'], "tax" => $tax);
369
+ }
370
+ else {
371
+ return false;
372
+ }
373
+
374
+ }
375
+ return $orderSet;
376
+ }
377
+ catch(Exception $e) {
378
+ Pb_Pbgsp_Model_Util::log("Received unexpected exception from Pb while calling createOrder.");
379
+ Pb_Pbgsp_Model_Util::logException($e);
380
+
381
+
382
+ }
383
+
384
+ }
385
+
386
+ private static function logIfError($object,$action=null) {
387
+ if(array_key_exists('errors',$object) && count($object['errors']) > 0) {
388
+ $processor = new Pb_Pbgsp_Model_Messages();
389
+ foreach($object['errors'] as $error) {
390
+ $message = '';
391
+ if(array_key_exists('message',$error))
392
+ $message = $error['message'];
393
+ $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
394
+ if($action)
395
+ Pb_Pbgsp_Model_Util::log("Error received in action $action");
396
+ Pb_Pbgsp_Model_Util::log($message);
397
+ }
398
+ return true;
399
+ }
400
+ return false;
401
+ }
402
+ public static function confirmOrder($orderNumber,$order) {
403
+ /* @var Mage_Sales_Model_Order $order */
404
+
405
+
406
+
407
+ $billingAddress = $order->getBillingAddress();
408
+ $confirm = array(
409
+ 'transactionId' => $order->getRealOrderId(),
410
+ 'merchantOrderNumber' => $order->getRealOrderId(),
411
+ 'purchaser' => array(
412
+ 'familyName' => $order->getCustomerLastname(),
413
+ 'givenName' => $order->getCustomerFirstname(),
414
+ 'email' => $order->getCustomerEmail(),
415
+ 'phoneNumbers' => array(
416
+ array(
417
+ 'number' => $billingAddress->getTelephone(),
418
+ 'type' => 'other'
419
+ )
420
+ )),
421
+ 'purchaserBillingAddress' => array(
422
+ 'street1' => $billingAddress->getStreet1(),
423
+ 'street2' => '',
424
+ 'city' => $billingAddress->getCity(),
425
+ 'countyOrRegion' => '',
426
+ 'provinceOrState' => $billingAddress->getRegionCode(),
427
+ 'country' => $billingAddress->getCountryId(),
428
+ 'postalOrZipCode' => $billingAddress->getPostcode(),
429
+ )
430
+
431
+ );
432
+ try {
433
+ $url = self::getCheckoutUrl("orders/$orderNumber/confirm");
434
+ $response = self::CallAPI('PUT',$url,$confirm);
435
+ Pb_Pbgsp_Model_Util::log("Passing $url ");
436
+ Pb_Pbgsp_Model_Util::log($confirm);
437
+ $confirmResponse = json_decode($response,true);
438
+ if(self::logIfError($confirmResponse,'confirmOrder'))//there is an error
439
+ return false;
440
+ return true;
441
+ }
442
+ catch(Exception $e) {
443
+ Pb_Pbgsp_Model_Util::log("Received unexpected exception from Pb while calling confirming order.");
444
+ Pb_Pbgsp_Model_Util::log($e->getMessage(). ' '. $e->getTraceAsString());
445
+ return false;
446
+ }
447
+ return true;
448
+ }
449
+
450
+ }
451
+
452
+ ?>
app/code/local/Pb/Pbgsp/Model/Carrier/ShippingMethod.php CHANGED
@@ -1,298 +1,304 @@
1
- <?php
2
-
3
- /**
4
- * Class Pb_Pbgsp_Model_Carrier_ShippingMethod
5
- */
6
- class Pb_Pbgsp_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
7
- {
8
- /**
9
- * unique internal shipping method identifier
10
- *
11
- * @var string [a-z0-9_]
12
- */
13
- protected $_code = 'pbgsp';
14
-
15
- public function getConfigData($field) {
16
- /* BigPixel 3/25/2012. hide errors for not applicable countries */
17
- /*if ($field == "showmethod") {
18
- // Make sure all errors are displayed.
19
- return 1;
20
- } else {
21
- return parent::getConfigData($field);
22
- }*/
23
- /*if ($field == "showmethod") {
24
- Pb_Pbgsp_Model_Util::log($field .':'. parent::getConfigData($field));
25
- Pb_Pbgsp_Model_Util::log($this->get_callstack());
26
- }*/
27
- return parent::getConfigData($field);
28
- }
29
-
30
- /**
31
- * @param $result
32
- * @param $errors
33
- * Adds custom error messages to $result
34
- */
35
- public function displayErrors($result,$quote) {
36
- $processor = new Pb_Pbgsp_Model_Messages();
37
- $isUnitErrorAdded = false;
38
-
39
- foreach($quote['quoteLines'] as $quoteLine) {
40
- if(array_key_exists('unitErrors',$quoteLine)) {
41
- foreach($quoteLine['unitErrors'] as $error) {
42
- $message = '';
43
- if(array_key_exists('message',$error))
44
- $message = $error['message'];
45
- $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
46
- $sku = $quoteLine['merchantComRefId'];
47
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
48
- $message = $message . " Please remove ". $product->getName() . " from cart.";
49
- $this->_addError($result,$message);
50
- $isUnitErrorAdded = true;
51
- }
52
-
53
- }
54
-
55
- }
56
- if(!$isUnitErrorAdded) {
57
- foreach($quote['errors'] as $error) {
58
- $message = '';
59
- if(array_key_exists('message',$error))
60
- $message = $error['message'];
61
- $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
62
- $this->_addError($result,$message);
63
- }
64
- }
65
-
66
- }
67
-
68
- private function _addError($result,$message) {
69
- $error = Mage::getModel('shipping/rate_result_error');
70
- $error->setCarrier('pbgsp');
71
- $error->setCarrierTitle("Pitney Bowes");
72
- $error->setErrorMessage($message);
73
- $result->append($error);
74
- Pb_Pbgsp_Model_Util::log("Added error $message");
75
- }
76
-
77
- /**
78
- * @param $index
79
- * @return string
80
- */
81
- private function getSku($index){
82
- $items = Mage::getSingleton('checkout/cart')->getItems();
83
- $i = 0;
84
- foreach ($items as $item):
85
- if($i++==$index):
86
- return $item->getSku();
87
- endif;
88
- endforeach;
89
- return '';
90
- }
91
-
92
- /**
93
- * @param $index
94
- * @return mixed
95
- */
96
- public function getRestrictId($index){
97
- $sku = $this->getSku($index);
98
- $id = Mage::getModel('catalog/product')->getIdBySku($sku);
99
- return $id;
100
- }
101
-
102
- private function _getShipMethodFromQuote($quote,$items) {
103
- $handlingFee = Pb_Pbgsp_Model_Credentials::getHandlingFee();
104
-
105
- $handlingoption = Pb_Pbgsp_Model_Credentials::getHandlingOption();
106
- $domesticShippingFee = Pb_Pbgsp_Model_Credentials::getDomesticShippingFee();
107
- $domesticShippingOption = Pb_Pbgsp_Model_Credentials::getDomesticShippingOption();
108
-
109
- $deliveryAdjMinDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMinDays();
110
- $deliveryAdjMixDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMaxDays();
111
- $totalQty = 0;
112
- foreach($items as $item) {
113
- $totalQty += $item->getQty();
114
- }
115
- if(isset($handlingoption) && $handlingoption == "2") { //apply as per item
116
- $handlingFee = $handlingFee * $totalQty;
117
- }
118
- if(isset($domesticShippingOption) && $domesticShippingOption == "2") { //apply as per item
119
- $domesticShippingFee = $domesticShippingFee * $totalQty;
120
- }
121
- $transportation = $quote['totalTransportation'];
122
- // create new instance of method rate
123
- $method = Mage::getModel('shipping/rate_result_method');
124
-
125
- // record carrier information
126
- $method->setCarrier($this->_code);
127
-
128
- // get config info
129
- $vv = Mage::getStoreConfig('carriers/pbgsp/title');
130
- $method->setCarrierTitle($vv);
131
-
132
- // record method information
133
- $title = $transportation['speed']." - ".(intval($transportation['minDays']) + $deliveryAdjMinDays)."-".(intval($transportation['maxDays']) + $deliveryAdjMixDays )." days";
134
- $method->setMethod($transportation['speed']);
135
- $method->setMethodTitle($title);
136
-
137
- // rate cost is optional property to record how much it costs to vendor to ship
138
- $method->setCost($transportation['shipping']['value']);
139
- $method->setPrice((floatval($transportation['total']['value']) + $handlingFee + $domesticShippingFee));
140
- $method->setTax($quote['totalImportation']['total']['value']);
141
- return $method;
142
- }
143
- private function _getCheapestShipMethod($quoteSet,$items)
144
- {
145
- $minPrice = -1;
146
- $minQuote = null;
147
- foreach ($quoteSet['quote'] as $quote) {
148
-
149
- if (array_key_exists('totalTransportation', $quote)) {
150
- $transportation = $quote['totalTransportation'];
151
- $cost = floatval($transportation['total']['value']);
152
- if($minPrice == -1 || $minPrice > $cost) {
153
- $minPrice = $cost;
154
- $minQuote = $quote;
155
-
156
- }
157
- }
158
-
159
- }
160
- return $this->_getShipMethodFromQuote($minQuote,$items);
161
- }
162
- /**
163
- * Collect rates for this shipping method based on information in $request
164
- *
165
- * @param Mage_Shipping_Model_Rate_Request $data
166
- * @return Mage_Shipping_Model_Rate_Result
167
- */
168
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
169
- {
170
- Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Carrier_ShippingMethod.collectRates ' . Mage::getStoreConfig('carriers/'.$this->_code.'/active'));
171
- // skip if not enabled
172
- if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
173
- return false;
174
- }
175
-
176
- // skip if the store is not located in the US
177
- Pb_Pbgsp_Model_Util::log($request->country_id);
178
- if ($request->country_id != "US") {
179
- return false;
180
- }
181
-
182
- // get necessary configuration values
183
-
184
-
185
- // this object will be returned as result of this method
186
- // containing all the shipping rates of this method
187
- $result = Mage::getModel('shipping/rate_result');
188
-
189
- $items = Mage::getSingleton('checkout/cart')->getItems();
190
- $address = Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress();
191
-
192
- if(!$items || count($items) == 0)
193
- $items = $request->getAllItems();
194
- if(!$address->getCountryId()) {
195
- $address->setCountryId($request->getDestCountryId());
196
- $address->setCity($request->getDestCity());
197
- $address->setStreet($request->getDestStreet());
198
- $address->setRegion($request->getDestRegionCode());
199
- $address->setPostcode($request->getDestPostcode());
200
- $address->setEmail('test@bigpixelstudio.com');
201
- $address->setFirstname('firstname');
202
- $address->setLastname('lastname');
203
- $address->setTelephone('1231231234');
204
-
205
- }
206
-
207
- // Clear all restrictions from previous calls
208
- Mage::getSingleton("customer/session")->setPbRestrictions(null);
209
- $allowSpecific = Mage::getStoreConfig('carriers/'.$this->_code .'/sallowspecific');
210
- if($allowSpecific) {
211
- $activeCountries = Mage::getStoreConfig('carriers/'.$this->_code .'/specificcountry');
212
-
213
- if(!(strpos($activeCountries,$address->getCountryId()) !== false)) {
214
- Pb_Pbgsp_Model_Util::log($address->getCountryId().' not found');
215
- return false;
216
- }
217
- }
218
-
219
-
220
- // NOTE: Insert calls to Magento Domestic Shipping costs here. Pass the newly calculated
221
- // domestic shipping costs to the API calls to get a proper full quote.
222
-
223
-
224
- if (!$address->getStreet1() || !$address->getCity()) {
225
- $address->setFirstname('firstname');
226
- $address->setLastname('lastname');
227
- $address->setCity('city');
228
- $address->setTelephone('phone');
229
- $address->setEmail('email@email.com');
230
- $address->setStreet(array('street'));
231
- }
232
-
233
- try {
234
-
235
- $shipMethodAvailable = false;
236
- $quoteSet = Pb_Pbgsp_Model_Api::getQuote($items, $address);
237
- $freeShippingEnabled = Mage::getStoreConfig('carriers/pbgsp/free_shipping_enable');
238
- $freeShippingSubTotal = Mage::getStoreConfig('carriers/pbgsp/free_shipping_subtotal');
239
-
240
- $totalOrderPrice = $this->getTotalOrderPrice($items);
241
- $shipMethods = array();
242
- foreach($quoteSet['quote'] as $quote) {
243
- if(array_key_exists('errors',$quote) && count($quote['errors']) > 0) {
244
- $this->displayErrors($result,$quote);
245
- }
246
- else if(array_key_exists('totalTransportation',$quote)) {
247
- if($freeShippingEnabled && $totalOrderPrice >= $freeShippingSubTotal) {
248
- //get cheapest shipping method from quoteSet
249
- $method = $this->_getCheapestShipMethod($quoteSet,$items);
250
- $method->setCost(0);
251
- $method->setPrice(0);
252
- $method->setTax(0);
253
- $result->append($method);
254
- array_push($shipMethods,$method);
255
- break;
256
- }
257
- else {
258
- $method = $this->_getShipMethodFromQuote($quote,$items);
259
- // add this rate to the result
260
- $result->append($method);
261
- array_push($shipMethods,$method);
262
- }
263
-
264
-
265
- $shipMethodAvailable = true;
266
- }
267
- }
268
- if($shipMethodAvailable) {
269
- Mage::getSingleton('checkout/session')->setPbMethods($shipMethods);
270
- }
271
- }
272
- catch(Exception $e) {
273
- Pb_Pbgsp_Model_Util::log("Error getting quotes");
274
- Pb_Pbgsp_Model_Util::logException($e);
275
- $message = $e->getMessage();
276
- if($e->getMessage() == '')
277
- $message = "Received unexpected error in getting quotes from Pbgsp. Please contact with administrator.";
278
- $this->_addError($result,$message);
279
-
280
- }
281
- return $result;
282
-
283
-
284
- }
285
-
286
- private function getTotalOrderPrice($products)
287
- {
288
- $totalOrderPrice = 0;
289
- foreach ($products as $product) {
290
- if ((!$product->getParentItem() && $product->getRealProductType() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) || ($product->getParentItem() && $product->isChildrenCalculated())) {
291
- $totalOrderPrice += $product->getPrice() * $product->getQty();
292
-
293
- }
294
- }
295
- return $totalOrderPrice;
296
- }
297
- }
298
- ?>
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Model/Carrier/ShippingMethod.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+ class Pb_Pbgsp_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
11
+ {
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'pbgsp';
18
+
19
+ public function getConfigData($field) {
20
+ /* BigPixel 3/25/2012. hide errors for not applicable countries */
21
+
22
+ return parent::getConfigData($field);
23
+ }
24
+
25
+ /**
26
+ * @param $result
27
+ * @param $errors
28
+ * Adds custom error messages to $result
29
+ */
30
+ public function displayErrors($result,$quote) {
31
+ $processor = new Pb_Pbgsp_Model_Messages();
32
+ $isUnitErrorAdded = false;
33
+
34
+ foreach($quote['quoteLines'] as $quoteLine) {
35
+ if(array_key_exists('unitErrors',$quoteLine)) {
36
+ foreach($quoteLine['unitErrors'] as $error) {
37
+ $message = '';
38
+ if(array_key_exists('message',$error))
39
+ $message = $error['message'];
40
+ $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
41
+ $sku = $quoteLine['merchantComRefId'];
42
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
43
+ $message = $message . " Please remove ". $product->getName() . " from cart.";
44
+ $this->_addError($result,$message);
45
+ $isUnitErrorAdded = true;
46
+ }
47
+
48
+ }
49
+
50
+ }
51
+ if(!$isUnitErrorAdded) {
52
+ foreach($quote['errors'] as $error) {
53
+ $message = '';
54
+ if(array_key_exists('message',$error))
55
+ $message = $error['message'];
56
+ $message = $processor->getDisplayMessage($error["error"],$message);//.$sku;
57
+ $this->_addError($result,$message);
58
+ }
59
+ }
60
+
61
+ }
62
+
63
+ private function _addError($result,$message) {
64
+ $error = Mage::getModel('shipping/rate_result_error');
65
+ $error->setCarrier('pbgsp');
66
+ $error->setCarrierTitle("Pitney Bowes");
67
+ $error->setErrorMessage($message);
68
+ $result->append($error);
69
+ Pb_Pbgsp_Model_Util::log("Added error $message");
70
+ }
71
+
72
+ /**
73
+ * @param $index
74
+ * @return string
75
+ */
76
+ private function getSku($index){
77
+ $items = Mage::getSingleton('checkout/cart')->getItems();
78
+ $i = 0;
79
+ foreach ($items as $item):
80
+ if($i++==$index):
81
+ return $item->getSku();
82
+ endif;
83
+ endforeach;
84
+ return '';
85
+ }
86
+
87
+ /**
88
+ * @param $index
89
+ * @return mixed
90
+ */
91
+ public function getRestrictId($index){
92
+ $sku = $this->getSku($index);
93
+ $id = Mage::getModel('catalog/product')->getIdBySku($sku);
94
+ return $id;
95
+ }
96
+
97
+ private function _getShipMethodFromQuote($quote,$items) {
98
+ $handlingFee = Pb_Pbgsp_Model_Credentials::getHandlingFee();
99
+
100
+ $handlingoption = Pb_Pbgsp_Model_Credentials::getHandlingOption();
101
+ $domesticShippingFee = Pb_Pbgsp_Model_Credentials::getDomesticShippingFee();
102
+ $domesticShippingOption = Pb_Pbgsp_Model_Credentials::getDomesticShippingOption();
103
+
104
+ $deliveryAdjMinDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMinDays();
105
+ $deliveryAdjMixDays = Pb_Pbgsp_Model_Credentials::getDeliveryAdjustmentMaxDays();
106
+ $totalQty = 0;
107
+ foreach($items as $item) {
108
+ $totalQty += $item->getQty();
109
+ }
110
+ if(isset($handlingoption) && $handlingoption == "2") { //apply as per item
111
+ $handlingFee = $handlingFee * $totalQty;
112
+ }
113
+ if(isset($domesticShippingOption) && $domesticShippingOption == "2") { //apply as per item
114
+ $domesticShippingFee = $domesticShippingFee * $totalQty;
115
+ }
116
+ $transportation = $quote['totalTransportation'];
117
+ // create new instance of method rate
118
+ $method = Mage::getModel('shipping/rate_result_method');
119
+
120
+ // record carrier information
121
+ $method->setCarrier($this->_code);
122
+
123
+ // get config info
124
+ $vv = Mage::getStoreConfig('carriers/pbgsp/title');
125
+ $method->setCarrierTitle($vv);
126
+
127
+ // record method information
128
+ $title = $transportation['speed']." - ".(intval($transportation['minDays']) + $deliveryAdjMinDays)."-".(intval($transportation['maxDays']) + $deliveryAdjMixDays )." days";
129
+ $method->setMethod($transportation['speed']);
130
+ $method->setMethodTitle($title);
131
+
132
+ // rate cost is optional property to record how much it costs to vendor to ship
133
+ $method->setCost($transportation['shipping']['value']);
134
+ $method->setPrice((floatval($transportation['total']['value']) + $handlingFee + $domesticShippingFee));
135
+
136
+ if(Pb_Pbgsp_Model_Credentials::isFreeTaxEnabled()) {
137
+ Pb_Pbgsp_Model_Util::log('Free tax enabled');
138
+ $method->setTax(0);
139
+ }
140
+
141
+ else {
142
+ Pb_Pbgsp_Model_Util::log('Free tax disabled');
143
+ $method->setTax($quote['totalImportation']['total']['value']);
144
+ }
145
+
146
+ return $method;
147
+ }
148
+ private function _getCheapestShipMethod($quoteSet,$items)
149
+ {
150
+ $minPrice = -1;
151
+ $minQuote = null;
152
+ foreach ($quoteSet['quote'] as $quote) {
153
+
154
+ if (array_key_exists('totalTransportation', $quote)) {
155
+ $transportation = $quote['totalTransportation'];
156
+ $cost = floatval($transportation['total']['value']);
157
+ if($minPrice == -1 || $minPrice > $cost) {
158
+ $minPrice = $cost;
159
+ $minQuote = $quote;
160
+
161
+ }
162
+ }
163
+
164
+ }
165
+ return $this->_getShipMethodFromQuote($minQuote,$items);
166
+ }
167
+ /**
168
+ * Collect rates for this shipping method based on information in $request
169
+ *
170
+ * @param Mage_Shipping_Model_Rate_Request $data
171
+ * @return Mage_Shipping_Model_Rate_Result
172
+ */
173
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
174
+ {
175
+ //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Carrier_ShippingMethod.collectRates ' . Mage::getStoreConfig('carriers/'.$this->_code.'/active'));
176
+ // skip if not enabled
177
+ if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
178
+ return false;
179
+ }
180
+
181
+ // skip if the store is not located in the US
182
+ Pb_Pbgsp_Model_Util::log($request->country_id);
183
+ if ($request->country_id != "US") {
184
+ return false;
185
+ }
186
+
187
+ // get necessary configuration values
188
+
189
+
190
+ // this object will be returned as result of this method
191
+ // containing all the shipping rates of this method
192
+ $result = Mage::getModel('shipping/rate_result');
193
+
194
+ $items = Mage::getSingleton('checkout/cart')->getItems();
195
+ $address = Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress();
196
+
197
+ if(!$items || count($items) == 0)
198
+ $items = $request->getAllItems();
199
+ if(!$address->getCountryId()) {
200
+ $address->setCountryId($request->getDestCountryId());
201
+ $address->setCity($request->getDestCity());
202
+ $address->setStreet($request->getDestStreet());
203
+ $address->setRegion($request->getDestRegionCode());
204
+ $address->setPostcode($request->getDestPostcode());
205
+ $address->setEmail('test@bigpixelstudio.com');
206
+ $address->setFirstname('firstname');
207
+ $address->setLastname('lastname');
208
+ $address->setTelephone('1231231234');
209
+
210
+ }
211
+
212
+ // Clear all restrictions from previous calls
213
+ Mage::getSingleton("customer/session")->setPbRestrictions(null);
214
+ $allowSpecific = Mage::getStoreConfig('carriers/'.$this->_code .'/sallowspecific');
215
+ if($allowSpecific) {
216
+ $activeCountries = Mage::getStoreConfig('carriers/'.$this->_code .'/specificcountry');
217
+
218
+ if(!(strpos($activeCountries,$address->getCountryId()) !== false)) {
219
+ Pb_Pbgsp_Model_Util::log($address->getCountryId().' not found');
220
+ return false;
221
+ }
222
+ }
223
+
224
+
225
+ // NOTE: Insert calls to Magento Domestic Shipping costs here. Pass the newly calculated
226
+ // domestic shipping costs to the API calls to get a proper full quote.
227
+
228
+
229
+ if (!$address->getStreet1() || !$address->getCity()) {
230
+ $address->setFirstname('firstname');
231
+ $address->setLastname('lastname');
232
+ $address->setCity('city');
233
+ $address->setTelephone('phone');
234
+ $address->setEmail('email@email.com');
235
+ $address->setStreet(array('street'));
236
+ }
237
+
238
+ try {
239
+
240
+ $shipMethodAvailable = false;
241
+ $quoteSet = Pb_Pbgsp_Model_Api::getQuote($items, $address);
242
+ $freeShippingEnabled = Mage::getStoreConfig('carriers/pbgsp/free_shipping_enable');
243
+ $freeShippingSubTotal = Mage::getStoreConfig('carriers/pbgsp/free_shipping_subtotal');
244
+
245
+ $totalOrderPrice = $this->getTotalOrderPrice($items);
246
+ $shipMethods = array();
247
+ foreach($quoteSet['quote'] as $quote) {
248
+ if(array_key_exists('errors',$quote) && count($quote['errors']) > 0) {
249
+ $this->displayErrors($result,$quote);
250
+ }
251
+ else if(array_key_exists('totalTransportation',$quote)) {
252
+ if($freeShippingEnabled && $totalOrderPrice >= $freeShippingSubTotal) {
253
+ //get cheapest shipping method from quoteSet
254
+ $method = $this->_getCheapestShipMethod($quoteSet,$items);
255
+ $method->setCost(0);
256
+ $method->setPrice(0);
257
+ $method->setTax(0);
258
+ $result->append($method);
259
+ array_push($shipMethods,$method);
260
+ break;
261
+ }
262
+ else {
263
+ $method = $this->_getShipMethodFromQuote($quote,$items);
264
+
265
+ // add this rate to the result
266
+ $result->append($method);
267
+ array_push($shipMethods,$method);
268
+ }
269
+
270
+
271
+ $shipMethodAvailable = true;
272
+ }
273
+ }
274
+ if($shipMethodAvailable) {
275
+ Mage::getSingleton('checkout/session')->setPbMethods($shipMethods);
276
+ }
277
+ }
278
+ catch(Exception $e) {
279
+ Pb_Pbgsp_Model_Util::log("Error getting quotes");
280
+ Pb_Pbgsp_Model_Util::logException($e);
281
+ //$message = $e->getMessage();
282
+ //if($e->getMessage() == '')
283
+ $message = "We've received an unexpected error while getting your quote. Please try again. If the error persists contact magentosupport@pb.com.";
284
+ $this->_addError($result,$message);
285
+
286
+ }
287
+ return $result;
288
+
289
+
290
+ }
291
+
292
+ private function getTotalOrderPrice($products)
293
+ {
294
+ $totalOrderPrice = 0;
295
+ foreach ($products as $product) {
296
+ if ((!$product->getParentItem() && $product->getRealProductType() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) || ($product->getParentItem() && $product->isChildrenCalculated())) {
297
+ $totalOrderPrice += $product->getPrice() * $product->getQty();
298
+
299
+ }
300
+ }
301
+ return $totalOrderPrice;
302
+ }
303
+ }
304
+ ?>
app/code/local/Pb/Pbgsp/Model/Catalog/Category.php CHANGED
@@ -1,128 +1,145 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Catalog_Category {
3
- protected $category;
4
- private static $roots;
5
- protected $url;
6
- public function __construct($id,$url=null) {
7
- if (gettype($id) == "object" && get_class($id) == "Mage_Catalog_Model_Category") {
8
- $this->category = $id;
9
- } else {
10
- $this->category = Mage::getModel('catalog/category')->load($id);
11
- }
12
- $this->url = $url;
13
- }
14
- public function getCategory() {
15
- return $this->category;
16
- }
17
- public function getName() {
18
- return $this->category->getName();
19
- }
20
-
21
- public function getCode() {
22
- return $this->category->getId();
23
- }
24
-
25
- public function getUrl() {
26
- //Pb_Pbgsp_Model_Util::log($this->category->getUrl());
27
- if($this->url)
28
- return $this->url;
29
- return $this->category->getUrl();
30
- //return Mage::app()->getStore($this->category->getStoreId())->getBaseUrl();
31
- }
32
-
33
- public function isRoot() {
34
- if (!$this->category->getParentId()) {
35
- return true;
36
- }
37
- if (!self::$roots) {
38
- $categoryOp = new Mage_Adminhtml_Block_Catalog_Category_Abstract();
39
- self::$roots = $categoryOp->getRootIds();
40
- }
41
- foreach (self::$roots as $rootId) {
42
- if ($this->getCode() == $rootId) {
43
- return true;
44
- }
45
- }
46
- return false;
47
- }
48
-
49
- public function getParentCode() {
50
- return $this->category->getParentId();
51
- }
52
-
53
- public function writeToFile($file) {
54
- $name = Pb_Pbgsp_Model_Catalog_File::stripHtml($this->getName());
55
- $name = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
56
- // $string = "<Category>\n";
57
- // $string .= "<CategoryCode>".htmlentities($this->getCode())."</CategoryCode>\n";
58
- // $string .= "<Name>".htmlentities($name)."</Name>\n";
59
- // //$string .= "<URL><![CDATA[".htmlentities($this->getUrl())."]]></URL>\n";
60
- // $string .= "<URL><![CDATA[".htmlentities($this->getUrl())."]]></URL>\n";
61
- // if($this->getParentCode() != 1 && !$this->isRoot()){
62
- // $string .= "<ParentCategoryCode>".htmlentities($this->getParentCode())."</ParentCategoryCode>\n";
63
- // }
64
- // $string .= "</Category>\n";
65
- //fputcsv($this->file,array('CATEGORY_ID','PARENT_CATEGORY_ID','NAME','ID_PATH','URL'));
66
- $parentCateID = '';
67
- if($this->getParentCode() != 1 && !$this->isRoot()){
68
- $parentCateID = $this->getParentCode();
69
- }
70
- fputcsv($file,array($this->getCode(),$parentCateID,$name,'',$this->getUrl()));
71
- //fwrite($file,$string);
72
- }
73
-
74
- // This is done via API
75
- public function upload() {
76
- echo "Uploading category: ".$this->category->getName()."... ";
77
- if (Pb_Pbgsp_Model_Api::addCategory($this)) {
78
- echo "ok";
79
- } else {
80
- echo "failed!";
81
- }
82
- echo "<br/>";
83
-
84
- $products = $this->category->getProductCollection();
85
- // TODO: Products that are part of multiple categories will be uploaded
86
- // multiple times.
87
- foreach ($products as $product) {
88
- $clearPathProduct = new Pb_Pbgsp_Model_Catalog_Product($product);
89
- echo "Uploading product: ".$clearPathProduct->getName()."... ";
90
- if (Pb_Pbgsp_Model_Api::addCommodity($clearPathProduct)) {
91
- echo "ok";
92
- } else {
93
- echo "failed!";
94
- }
95
- echo "<br/>";
96
- }
97
-
98
-
99
- $children = $this->category->getChildrenCategories();
100
-
101
- // TODO: this code will run out of memory if there are a lot of categories....
102
- // Need to convert the recursive call to a loop at some point.
103
- foreach ($children as $child) {
104
- $childCategory = new Pb_Pbgsp_Model_Catalog_Category($child);
105
- $childCategory->upload();
106
- }
107
- }
108
-
109
- // This fuction starts at the Magento root and its not very efficient... see isRoot for proper implementation.
110
- // This function is only used by the API upload.
111
- public static function getAllRootCategories() {
112
- $roots = array();
113
-
114
- $categories = Mage::getModel('catalog/category')->getCollection();//->getSelect()->order(array('IF(`id`>0, `id`, 9999) ASC'));
115
- $categories = $categories->getIterator();
116
-
117
- foreach ($categories as $category) {
118
- $parents = $category->getParentId();
119
- if (!$parents) {
120
- $rootCategory = new Pb_Pbgsp_Model_Catalog_Category($category->getId());
121
- array_push($roots,$rootCategory);
122
- }
123
- }
124
- return $roots;
125
- }
126
-
127
- }
128
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Catalog/Category.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Catalog_Category {
10
+ protected $category;
11
+ private static $roots;
12
+ protected $url;
13
+ public function __construct($id,$url=null) {
14
+ if (gettype($id) == "object" && get_class($id) == "Mage_Catalog_Model_Category") {
15
+ $this->category = $id;
16
+ } else {
17
+ $this->category = Mage::getModel('catalog/category')->load($id);
18
+ }
19
+ $this->url = $url;
20
+ }
21
+ public function getCategory() {
22
+ return $this->category;
23
+ }
24
+ public function getName() {
25
+ return $this->category->getName();
26
+ }
27
+
28
+ public function getCode() {
29
+ return $this->category->getId();
30
+ }
31
+
32
+ public function getUrl() {
33
+ //Pb_Pbgsp_Model_Util::log($this->category->getUrl());
34
+ if($this->url)
35
+ return $this->url;
36
+ return $this->category->getUrl();
37
+ //return Mage::app()->getStore($this->category->getStoreId())->getBaseUrl();
38
+ }
39
+
40
+ public function isRoot() {
41
+ if (!$this->category->getParentId()) {
42
+ return true;
43
+ }
44
+ if (!self::$roots) {
45
+ $categoryOp = new Mage_Adminhtml_Block_Catalog_Category_Abstract();
46
+ self::$roots = $categoryOp->getRootIds();
47
+ }
48
+ foreach (self::$roots as $rootId) {
49
+ if ($this->getCode() == $rootId) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+
56
+ public function getParentCode() {
57
+ return $this->category->getParentId();
58
+ }
59
+ private function _shouldUpload($lastDiff) {
60
+
61
+ Pb_Pbgsp_Model_Util::log($this->category->getPbPbgspUploadActive());
62
+ if(!$this->category->getPbPbgspUploadActive()) return false;
63
+ $lastUpload = $this -> category -> getPbPbgspUpload();
64
+ //Pb_Pbgsp_Model_Util::log('Product '. $this -> getSKU() . ' lastUpload='. $lastUpload . ' '. date('m-d-Y H:i:s',$lastUpload));
65
+ if (!$lastUpload) {
66
+ // First upload.
67
+ return true;
68
+ } else if ($lastDiff <= $lastUpload - (30 * 60)) {
69
+ // Added after the last diff
70
+ return true;
71
+ } else {
72
+ return false;
73
+ }
74
+ }
75
+ public function writeToFile($file,$lastDiff) {
76
+ if($this->_shouldUpload($lastDiff)) {
77
+ $name = Pb_Pbgsp_Model_Catalog_File::stripHtml($this->getName());
78
+ $name = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
79
+
80
+ $parentCateID = '';
81
+ if($this->getParentCode() != 1 && !$this->isRoot()){
82
+ $parentCateID = $this->getParentCode();
83
+ }
84
+ fputcsv($file,array($this->getCode(),$parentCateID,$name,'',$this->getUrl()));
85
+ return true;
86
+ }
87
+ return false;
88
+
89
+ }
90
+
91
+ // This is done via API
92
+ public function upload() {
93
+ echo "Uploading category: ".$this->category->getName()."... ";
94
+ if (Pb_Pbgsp_Model_Api::addCategory($this)) {
95
+ echo "ok";
96
+ } else {
97
+ echo "failed!";
98
+ }
99
+ echo "<br/>";
100
+
101
+ $products = $this->category->getProductCollection();
102
+ // TODO: Products that are part of multiple categories will be uploaded
103
+ // multiple times.
104
+ foreach ($products as $product) {
105
+ $clearPathProduct = new Pb_Pbgsp_Model_Catalog_Product($product);
106
+ echo "Uploading product: ".$clearPathProduct->getName()."... ";
107
+ if (Pb_Pbgsp_Model_Api::addCommodity($clearPathProduct)) {
108
+ echo "ok";
109
+ } else {
110
+ echo "failed!";
111
+ }
112
+ echo "<br/>";
113
+ }
114
+
115
+
116
+ $children = $this->category->getChildrenCategories();
117
+
118
+ // TODO: this code will run out of memory if there are a lot of categories....
119
+ // Need to convert the recursive call to a loop at some point.
120
+ foreach ($children as $child) {
121
+ $childCategory = new Pb_Pbgsp_Model_Catalog_Category($child);
122
+ $childCategory->upload();
123
+ }
124
+ }
125
+
126
+ // This fuction starts at the Magento root and its not very efficient... see isRoot for proper implementation.
127
+ // This function is only used by the API upload.
128
+ public static function getAllRootCategories() {
129
+ $roots = array();
130
+
131
+ $categories = Mage::getModel('catalog/category')->getCollection();//->getSelect()->order(array('IF(`id`>0, `id`, 9999) ASC'));
132
+ $categories = $categories->getIterator();
133
+
134
+ foreach ($categories as $category) {
135
+ $parents = $category->getParentId();
136
+ if (!$parents) {
137
+ $rootCategory = new Pb_Pbgsp_Model_Catalog_Category($category->getId());
138
+ array_push($roots,$rootCategory);
139
+ }
140
+ }
141
+ return $roots;
142
+ }
143
+
144
+ }
145
+ ?>
app/code/local/Pb/Pbgsp/Model/Catalog/Cron.php CHANGED
@@ -1,95 +1,102 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Catalog_Cron {
3
-
4
- private $lastDiff;
5
- private $lastFull;
6
-
7
-
8
-
9
- public function catalogSync() {
10
- Pb_Pbgsp_Model_Util::log("Start Sync...");
11
- $diffPeriod = Mage::getStoreConfig('carriers/pbgsp/catalog_diff');
12
- $fullPeriod = Mage::getStoreConfig('carriers/pbgsp/catalog_full');
13
-
14
- $collection = Mage::getModel("pb_pbgsp/variable")->getCollection();
15
- foreach ($collection as $variable) {
16
- Pb_Pbgsp_Model_Util::log($variable->getName()." -> ".$variable->getValue());
17
- if ($variable->getName() == "lastFull") {
18
- $this->lastFull = $variable;
19
- }
20
- if ($variable->getName() == "lastDiff") {
21
- $this->lastDiff = $variable;
22
- }
23
- }
24
-
25
-
26
- $appRoot = Mage::getRoot();
27
- $mageRoot = dirname($appRoot);
28
- $configOptions = Mage::getModel('core/config_options');
29
- $configOptions->createDirIfNotExists($mageRoot.'/var/pbgsp');
30
- chmod($mageRoot . '/var/pbgsp/', 0777);
31
-
32
- if (!isset($this->lastFull) || $this->lastFull->getValue() < time() - $fullPeriod*24*3600) {
33
- // Full catalog upload needed
34
- $this->uploadCatalog();
35
- } else if (!isset($this->lastDiff) && $this->lastFull->getValue() < time() - $diffPeriod*3600) {
36
- // First catalog diff upload
37
- $this->uploadCatalog($this->lastFull);
38
- } else if (isset($this->lastDiff) && ($this->lastDiff->getValue() < time() - $diffPeriod*3600 &&
39
- $this->lastFull->getValue() < time() - $diffPeriod*3600)) {
40
- // Catalog diff upload
41
- $this->uploadCatalog($this->lastDiff);
42
- }
43
- else {
44
- Pb_Pbgsp_Model_Util::log('PB Export cron. Do not export catalog');
45
-
46
- }
47
-
48
- }
49
-
50
- public function uploadCatalog($lastDiff = false) {
51
- if (!$lastDiff) {
52
- Pb_Pbgsp_Model_Util::log("Full catalog upload");
53
- $file = new Pb_Pbgsp_Model_Catalog_File();
54
- if (isset($this->lastFull)) {
55
- $this->lastFull->setValue(time());
56
- } else {
57
- $this->lastFull = Mage::getModel("pb_pbgsp/variable");
58
- $this->lastFull->setName("lastFull");
59
- $this->lastFull->setValue(time());
60
- }
61
- $this->lastFull->save();
62
- } else {
63
- Pb_Pbgsp_Model_Util::log("catalog diff");
64
- $file = new Pb_Pbgsp_Model_Catalog_File($lastDiff->getValue());
65
- if (isset($this->lastDiff)) {
66
- $this->lastDiff->setValue(time());
67
- } else {
68
- $this->lastDiff = Mage::getModel("pb_pbgsp/variable");
69
- $this->lastDiff->setName("lastDiff");
70
- $this->lastDiff->setValue(time());
71
- }
72
- $this->lastDiff->save();
73
- }
74
-
75
- Pb_Pbgsp_Model_Util::log("RAY:Create Function Started");
76
-
77
- $file->createNew();
78
-
79
- Pb_Pbgsp_Model_Util::log("RAY:Create Function Complete");
80
-
81
- Pb_Pbgsp_Model_Util::log("RAY:upload Started");
82
- $file->upload();
83
- $file->logProdWithoutCategories();
84
- Pb_Pbgsp_Model_Util::log("RAY:upload Complete");
85
- }
86
-
87
- public function processStatusNotifications() {
88
- $file = new Pb_Pbgsp_Model_Catalog_File();
89
- $file->processStatusNotifications();
90
- }
91
-
92
- }
93
-
94
-
95
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Catalog/Cron.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Catalog_Cron {
10
+
11
+ private $lastDiff;
12
+ private $lastFull;
13
+
14
+
15
+
16
+ public function catalogSync() {
17
+ Pb_Pbgsp_Model_Util::log("Start Sync...");
18
+ $diffPeriod = Mage::getStoreConfig('carriers/pbgsp/catalog_diff');
19
+ $fullPeriod = Mage::getStoreConfig('carriers/pbgsp/catalog_full');
20
+
21
+ $collection = Mage::getModel("pb_pbgsp/variable")->getCollection();
22
+ foreach ($collection as $variable) {
23
+ Pb_Pbgsp_Model_Util::log($variable->getName()." -> ".$variable->getValue());
24
+ if ($variable->getName() == "lastFull") {
25
+ $this->lastFull = $variable;
26
+ }
27
+ if ($variable->getName() == "lastDiff") {
28
+ $this->lastDiff = $variable;
29
+ }
30
+ }
31
+
32
+
33
+ $appRoot = Mage::getRoot();
34
+ $mageRoot = dirname($appRoot);
35
+ $configOptions = Mage::getModel('core/config_options');
36
+ $configOptions->createDirIfNotExists($mageRoot.'/var/pbgsp');
37
+ chmod($mageRoot . '/var/pbgsp/', 0777);
38
+
39
+ if (!isset($this->lastFull) || $this->lastFull->getValue() < time() - $fullPeriod*24*3600) {
40
+ // Full catalog upload needed
41
+ $this->uploadCatalog();
42
+ } else if (!isset($this->lastDiff) && $this->lastFull->getValue() < time() - $diffPeriod*3600) {
43
+ // First catalog diff upload
44
+ $this->uploadCatalog($this->lastFull);
45
+ } else if (isset($this->lastDiff) && ($this->lastDiff->getValue() < time() - $diffPeriod*3600 &&
46
+ $this->lastFull->getValue() < time() - $diffPeriod*3600)) {
47
+ // Catalog diff upload
48
+ $this->uploadCatalog($this->lastDiff);
49
+ }
50
+ else {
51
+ Pb_Pbgsp_Model_Util::log('PB Export cron. Do not export catalog');
52
+
53
+ }
54
+
55
+ }
56
+
57
+ public function uploadCatalog($lastDiff = false) {
58
+ if (!$lastDiff) {
59
+ Pb_Pbgsp_Model_Util::log("Full catalog upload");
60
+ $file = new Pb_Pbgsp_Model_Catalog_File();
61
+ if (isset($this->lastFull)) {
62
+ $this->lastFull->setValue(time());
63
+ } else {
64
+ $this->lastFull = Mage::getModel("pb_pbgsp/variable");
65
+ $this->lastFull->setName("lastFull");
66
+ $this->lastFull->setValue(time());
67
+ }
68
+ $this->lastFull->save();
69
+ } else {
70
+ Pb_Pbgsp_Model_Util::log("catalog diff");
71
+ $file = new Pb_Pbgsp_Model_Catalog_File($lastDiff->getValue());
72
+ if (isset($this->lastDiff)) {
73
+ $this->lastDiff->setValue(time());
74
+ } else {
75
+ $this->lastDiff = Mage::getModel("pb_pbgsp/variable");
76
+ $this->lastDiff->setName("lastDiff");
77
+ $this->lastDiff->setValue(time());
78
+ }
79
+ $this->lastDiff->save();
80
+ }
81
+
82
+ Pb_Pbgsp_Model_Util::log("RAY:Create Function Started");
83
+
84
+ $file->createNew();
85
+
86
+ Pb_Pbgsp_Model_Util::log("RAY:Create Function Complete");
87
+
88
+ Pb_Pbgsp_Model_Util::log("RAY:upload Started");
89
+ $file->upload();
90
+ $file->logProdWithoutCategories();
91
+ Pb_Pbgsp_Model_Util::log("RAY:upload Complete");
92
+ }
93
+
94
+ public function processStatusNotifications() {
95
+ $file = new Pb_Pbgsp_Model_Catalog_File();
96
+ $file->processStatusNotifications();
97
+ }
98
+
99
+ }
100
+
101
+
102
+ ?>
app/code/local/Pb/Pbgsp/Model/Catalog/File.php CHANGED
@@ -1,673 +1,728 @@
1
- <?php
2
-
3
- /* Creates a temporary file containing a Pb catalog xml file. Because of possible PHP timeouts the creation of the
4
- * xml file is done in concrete steps that can be resumed in case of a timeout.
5
- */
6
-
7
- class Pb_Pbgsp_Model_Catalog_File {
8
-
9
-
10
- private $file;
11
- private $filename;
12
- private $lastDiff;
13
- private $productIds;
14
- private $lastFileName;
15
-
16
- public function __construct($lastDiff = false) {
17
- $this->lastDiff = $lastDiff;
18
- $this->productIds = array();
19
- }
20
-
21
- private function _getTempDir() {
22
- $appRoot = Mage::getRoot();
23
- $mageRoot = dirname($appRoot);
24
- $configOptions = Mage::getModel('core/config_options');
25
- $tmpDir = $mageRoot . '/var/pbgsp/tmp/';
26
- $configOptions->createDirIfNotExists( $tmpDir);
27
- chmod($tmpDir, 0777);
28
- return $tmpDir;
29
- }
30
-
31
-
32
- private function _getDataFileName($dataFeedName,$part=null) {
33
- $partName = '';
34
- if($part)
35
- $partName = '_part'.$part;
36
- $fileName = Pb_Pbgsp_Model_Credentials::getCatalogSenderID() . "_".$dataFeedName."_update_". Pb_Pbgsp_Model_Credentials::getPBID().'_'.date('Ymd_His').'_'.mt_rand(100000, 999999);
37
- if($part == 1)
38
- $this->lastFileName = $fileName;
39
- else
40
- $fileName = $this->lastFileName;
41
- return $fileName.$partName.'.csv';
42
- }
43
- private function _createNewCommoditiyFile($part=null) {
44
- $fileName = $this->_getDataFileName('catalog',$part);
45
-
46
-
47
- $this->filename = $this->_getTempDir().$fileName;
48
- $this->file = fopen($this->filename,"w+");
49
- chmod($this->filename, 0777);
50
- //add header row
51
- fputcsv($this->file,array('MERCHANT_COMMODITY_REF_ID','COMMODITY_NAME_TITLE','SHORT_DESCRIPTION',
52
- 'LONG_DESCRIPTION','RETAILER_ID','COMMODITY_URL','RETAILER_UNIQUE_ID','PCH_CATEGORY_ID',
53
- 'RH_CATEGORY_ID','STANDARD_PRICE','WEIGHT_UNIT','DISTANCE_UNIT','COO','IMAGE_URL','PARENT_SKU',
54
- 'CHILD_SKU','PARCELS_PER_SKU','UPC','UPC_CHECK_DIGIT','GTIN','MPN','ISBN','BRAND','MANUFACTURER',
55
- 'MODEL_NUMBER','MANUFACTURER_STOCK_NUMBER','COMMODITY_CONDITION','COMMODITY_HEIGHT',
56
- 'COMMODITY_WIDTH','COMMODITY_LENGTH','PACKAGE_WEIGHT','PACKAGE_HEIGHT','PACKAGE_WIDTH',
57
- 'PACKAGE_LENGTH','HAZMAT','ORMD','CHEMICAL_INDICATOR','PESTICIDE_INDICATOR','AEROSOL_INDICATOR',
58
- 'RPPC_INDICATOR','BATTERY_TYPE','NON_SPILLABLE_BATTERY','FUEL_RESTRICTION','SHIP_ALONE',
59
- 'RH_CATEGORY_ID_PATH','RH_CATEGORY_NAME_PATH'));//,'RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT','HS_CODE','CURRENCY'
60
-
61
- fflush($this->file);
62
- }
63
- private function _createNewCategoryFile($part=null) {
64
- $fileName = $this->_getDataFileName('category-tree',$part);
65
-
66
-
67
- $this->filename = $this->_getTempDir().$fileName;
68
- $this->file = fopen($this->filename,"w+");
69
- chmod($this->filename, 0777);
70
- //add header row
71
- fputcsv($this->file,array('CATEGORY_ID','PARENT_CATEGORY_ID','NAME',
72
- 'ID_PATH','URL'));
73
-
74
- fflush($this->file);
75
- }
76
-
77
-
78
-
79
-
80
- private function _getSelectedCategory($categories,$catId) {
81
- foreach($categories as $cat) {
82
- if($cat->getId() == $catId)
83
- return $cat;
84
- }
85
- return false;
86
- }
87
- /**
88
- * Extracts the categories and products and exports them into xml file.
89
- */
90
- public function createNew() {
91
-
92
- $maxRecordsCount = Pb_Pbgsp_Model_Credentials::getMaxRecordsCount();
93
- if(!$maxRecordsCount)
94
- $maxRecordsCount = 10000;
95
-
96
- $prodCount = 0;
97
- $catCount = 0;
98
- $fileRecordCount = 0;
99
- //get stores which has disabled clearpath
100
- $stores = Mage::app()->getStores();
101
- $defaultStoreUrl = Mage::getBaseUrl();
102
- $secDefaultStoreUrl = str_replace("http","https",$defaultStoreUrl);
103
- $disabledStores = array();
104
- $addedCategories = array();
105
- $part=1;
106
- foreach($stores as $store) {
107
-
108
- $isActive = Mage::getStoreConfig('carriers/pbgsp/active',$store);
109
- $baseURL = $store->getBaseUrl();
110
-
111
- if(!$isActive) {
112
- $disabledStores[] = $store;
113
- Pb_Pbgsp_Model_Util::log("Disabled store". $store->getId(). ' '. $store->getCode());
114
- }
115
- else {
116
- $rootId = Mage::app()->getStore($store->getId())->getRootCategoryId();
117
- $rootCat = Mage::getModel('catalog/category')->load($rootId);
118
- /* @var $rootCat Mage_Catalog_Model_Category */
119
- $rootCat->setData('store',$store);
120
- Pb_Pbgsp_Model_Util::log("Default store url $defaultStoreUrl store ".$store->getCode()." store base url".
121
- $baseURL." root cat url". $rootCat->getUrl(). " cat name". $rootCat->getName());
122
- $catUrl = str_replace($defaultStoreUrl,$baseURL,$rootCat->getUrl());
123
- if($catUrl == $rootCat->getUrl())
124
- $catUrl = str_replace($secDefaultStoreUrl,$baseURL,$rootCat->getUrl());
125
- $cat = new Pb_Pbgsp_Model_Catalog_Category($rootCat,$catUrl);
126
- if(!$this->file || $fileRecordCount > $maxRecordsCount)
127
- {
128
- $this->_createNewCategoryFile($part);
129
- $fileRecordCount=0;
130
- $part++;
131
- }
132
- $cat->writeToFile($this->file);
133
- fflush($this->file);
134
- $catCount++;
135
- $fileRecordCount++;
136
- $categories = Mage::getModel('catalog/category')
137
- ->getCollection()
138
- ->addUrlRewriteToResult()
139
- ->addAttributeToSelect('name')
140
- ->addFieldToFilter('path', array('like'=> "1/$rootId/%"));
141
- $addedCategories[] = $rootCat;
142
-
143
- foreach($categories as $category) {
144
- if(!$this->file || $fileRecordCount > $maxRecordsCount)
145
- {
146
- $this->_createNewCategoryFile($part);
147
- $fileRecordCount=0;
148
- $part++;
149
- }
150
- /* @var $category Mage_Catalog_Model_Category */
151
- $category->setStoreId($store->getId());
152
- $category->setData('store',$store);
153
- $addedCategories[] = $category;
154
-
155
-
156
-
157
-
158
- $catUrl = str_replace($defaultStoreUrl,$baseURL,$category->getUrl());
159
- if($catUrl == $category->getUrl())
160
- $catUrl = str_replace($secDefaultStoreUrl,$baseURL,$category->getUrl());
161
- $cat = new Pb_Pbgsp_Model_Catalog_Category($category,$catUrl);
162
- $cat->writeToFile($this->file);
163
- fflush($this->file);
164
- $catCount++;
165
- $fileRecordCount++;
166
- }
167
- }
168
- }
169
-
170
- fclose($this->file);
171
- $this->_stripPartFromFileName($part);
172
- //fwrite($this->file,"</CategoryList>\n<CommodityList>\n");
173
- $fileRecordCount=0;
174
- $part=1;
175
- $this->_createNewCommoditiyFile($part);
176
- $part++;
177
- $addedProducts = array();
178
- foreach($addedCategories as $category) {
179
- //Mage::app()->setCurrentStore($category->getStoreId());
180
-
181
- $count = Mage::getModel('catalog/product')->getCollection()
182
- ->addCategoryFilter($category)
183
- ->count();
184
- $pageSize = 400;
185
- $currIndex = 0;
186
- while($currIndex < $count) {
187
- $productCollection = Mage::getModel('catalog/product')->getCollection()
188
-
189
- ->addCategoryFilter($category)
190
-
191
- ->addAttributeToSelect('name')
192
- ->addAttributeToSelect('sku')
193
- ->addAttributeToSelect('country_of_manufacture')
194
- ->addAttributeToSelect('description')
195
- ->addAttributeToSelect('product_url')
196
- ->addAttributeToSelect('type_id')
197
- ->addAttributeToSelect('pb_pbgsp_upload')
198
- // ->addUrlRewrite($category->getId()) //this will add the url rewrite.
199
- ->addAttributeToSelect('price')
200
- ->addAttributeToSelect('weight');
201
-
202
- $baseURL = Mage::app()->getStore($category->getStoreId())->getBaseUrl();
203
- $productUrlFormat = $baseURL ."catalog/product/view/id/%d/";
204
- foreach($productCollection as $product) {
205
- /* @var $product Mage_Catalog_Model_Product */
206
- if($product->getTypeId() == 'virtual')
207
- continue;
208
- $cateIds = $product->getCategoryIds();
209
- $cateId = 0;
210
- foreach($cateIds as $cId) {
211
- $cateId = $cId;//get lower level of category
212
- }
213
- $prodCat = $this->_getSelectedCategory($addedCategories,$cateId);
214
- if(!$prodCat)
215
- $prodCat = $category;
216
- $cIds = explode('/',$prodCat->getPath());
217
- $cIds = array_slice($cIds,1);//remove root category
218
- $prodCat->setData('id_path',implode(':',$cIds));
219
- $prodCat->setData('name_path',$this->_getCatNamePath($addedCategories,$cIds));
220
- if($product->getTypeId() == 'configurable' ) {
221
- $productType = $product->getTypeInstance(true);
222
- $allowedProducts = $productType->getUsedProducts(null, $product);
223
- /** @var $childProduct Mage_Catalog_Model_Product */
224
-
225
- foreach($allowedProducts as $childProduct) {
226
- if(!array_key_exists($childProduct->getSku(),$addedProducts)) {
227
- if( $fileRecordCount > $maxRecordsCount)
228
- {
229
- $this->_createNewCommoditiyFile($part);
230
- $fileRecordCount=0;
231
- $part++;
232
- }
233
- $pbChildProduct = new Pb_Pbgsp_Model_Catalog_Product($childProduct->getId(),sprintf($productUrlFormat,$product->getId()));
234
- $this->writeProduct($pbChildProduct,$cateId,$product->getSku(),$prodCat);
235
- $addedProducts[$childProduct->getSku()] = "added";
236
- $prodCount++;
237
- $fileRecordCount++;
238
- }
239
- }
240
- }
241
- else {
242
- if(!array_key_exists($product->getSku(),$addedProducts)) {
243
- $pbProduct = new Pb_Pbgsp_Model_Catalog_Product($product,sprintf($productUrlFormat,$product->getId()));
244
- if( $fileRecordCount > $maxRecordsCount)
245
- {
246
- $this->_createNewCommoditiyFile();
247
- $fileRecordCount=0;
248
- $part++;
249
- }
250
- $this->writeProduct($pbProduct,$cateId,null,$prodCat);
251
- $prodCount++;
252
- $fileRecordCount++;
253
- $addedProducts[$product->getSku()] = "added";
254
-
255
- }
256
-
257
-
258
- }
259
-
260
-
261
- }
262
- $currIndex += $pageSize;
263
-
264
- }
265
- }
266
-
267
-
268
-
269
- // fwrite($this->file,"</CommodityList>\n</Catalog>\n");
270
- fflush($this->file);
271
-
272
- $this->_stripPartFromFileName($part);
273
- }
274
-
275
- private function _getCatNamePath($categories,$cateIds) {
276
-
277
- $names = array();
278
- foreach($cateIds as $id) {
279
- foreach($categories as $cat) {
280
- if($cat->getId() == $id) {
281
- array_push($names, $cat->getName());
282
- break;
283
- }
284
- }
285
- }
286
- // Pb_Pbgsp_Model_Util::log($names);
287
- return implode('|',$names);
288
- }
289
-
290
- /**
291
- * Updates the pb_pbgsp_upload time in all uploaded products
292
- */
293
- public function updateLastProductUpload() {
294
-
295
- $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'pb_pbgsp_upload');
296
- if(!$attribute->getAttributeId()) {
297
- $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
298
- $setup->addAttribute('catalog_product', 'pb_pbgsp_upload', array(
299
- 'label' => 'Last Pb upload timestampt',
300
- 'type' => 'varchar',
301
- 'input' => 'text',
302
- 'visible' => false,
303
- 'required' => false,
304
- 'position' => 1,
305
- ));
306
- }
307
-
308
- $productIds = array_unique($this->productIds);
309
- Pb_Pbgsp_Model_Util::log('Uploaded products' . count($productIds));
310
- $updated = 0;
311
- foreach ($productIds as $prodId) {
312
- $product = Mage::getModel("catalog/product")->load($prodId);
313
- //Pb_Pbgsp_Model_Util::log('Updating product '. $product->getSKU());
314
- $product->setPbPbgspUpload(time());
315
- try{
316
- $product->save();
317
- $updated++;
318
- }catch(Exception $e){
319
- Pb_Pbgsp_Model_Util::log("There was a problem saving the product with sku ". $product->getSku() ." Error Message \n" . $e->getMessage());
320
- }
321
-
322
- //Pb_Pbgsp_Model_Util::log($product->getId()." ".$product->getName()." ".$product->getPbPbgspUpload());
323
- }
324
- Pb_Pbgsp_Model_Util::log("$updated products' pb_pbgsp_upload updated");
325
- }
326
-
327
- /**
328
- * Uploads the xml file to clearpath SFTP server
329
- */
330
-
331
- private function _getNotificationDir() {
332
- $tmpDir = $this->_getTempDir();
333
- $configOptions = Mage::getModel('core/config_options');
334
- $notificationDir = $tmpDir . 'notifications';
335
- $configOptions->createDirIfNotExists( $notificationDir);
336
- chmod($notificationDir, 0777);
337
- return $notificationDir;
338
- }
339
-
340
- public function processStatusNotifications() {
341
- try {
342
-
343
- $adminEmail = Pb_Pbgsp_Model_Credentials::getAdminEmail();
344
- if(!isset($adminEmail) || $adminEmail=='')
345
- return;
346
- $notificationDir = $this->_getNotificationDir();
347
- $this->_downloadStatusNotifications($notificationDir);
348
- $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
349
- if(count($notificationFiles) > 0) {
350
- $mail = new Zend_Mail();
351
- $mail->setFrom('no-reply@pb.com','Pitney Bowes');
352
- $mail->addTo($adminEmail)
353
- ->setSubject('Catalog Export Error')
354
- ->setBodyText('Catalog Export Error. Please see attached files.');
355
- $fileCount = 0;
356
- foreach($notificationFiles as $notificationFile) {
357
- if($this->_endsWith($notificationFile,'.err') || $this->_endsWith($notificationFile,'.log') ) {
358
- $file = $notificationDir.'/'. $notificationFile;
359
- $at = new Zend_Mime_Part(file_get_contents($file));
360
- $at->filename = basename($file);
361
- $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
362
- $at->encoding = Zend_Mime::ENCODING_8BIT;
363
-
364
- $mail->addAttachment($at);
365
- $fileCount++;
366
- }
367
-
368
- }
369
- if($fileCount > 0) {
370
- $mail->send();
371
- Pb_Pbgsp_Model_Util::log("Email sent with error files.");
372
- }
373
-
374
- else {
375
- Pb_Pbgsp_Model_Util::log(" No error files found.");
376
- }
377
- //keep these files until next upload and delete files from old upload
378
- $this->_cleanNotificationFiles();
379
- }
380
- }
381
- catch (Exception $e) {
382
- Pb_Pbgsp_Model_Util::log("Error in processStatusNotifications:". $e->getMessage());
383
- Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
384
-
385
- }
386
-
387
- }
388
- private function _cleanNotificationFiles() {
389
- //keep resent files until next upload and delete files from old upload
390
- $lastExportedFiles = $this->_getLastExportedFileNames();
391
- if(!$lastExportedFiles)
392
- return;
393
- $notificationDir = $this->_getNotificationDir();
394
- $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
395
-
396
- foreach($notificationFiles as $notificationFile) {
397
- $path_parts = pathinfo($notificationFile);
398
- $localFileNameWithoutExt = $path_parts['filename'];
399
- $isOldFile = true;
400
- foreach($lastExportedFiles as $lastExportedFile) {
401
- $lastExportedFileNameWithoutExt = str_replace('.gpg','',str_replace('.csv','',$lastExportedFile));
402
- if($lastExportedFileNameWithoutExt == $localFileNameWithoutExt) {
403
- $isOldFile = false;
404
- break;
405
- }
406
- }
407
- if($isOldFile) {
408
- //this is from 2nd last upload, remove it from disk
409
- unlink($notificationDir.'/'.$notificationFile);
410
- }
411
- }
412
-
413
- }
414
- private function _downloadStatusNotifications($notificationDir) {
415
-
416
- $credentials = $this->_getSftpCredentials();
417
- try {
418
- $sftpDumpFile = new Varien_Io_Sftp();
419
- $sftpDumpFile->open(
420
- $credentials
421
- );
422
- $rootDir = Pb_Pbgsp_Model_Credentials::getSftpCatalogDirectory();
423
- if(!$this->_endsWith($rootDir,'/'))
424
- $rootDir = $rootDir.'/';
425
- $processedDir = $rootDir.'outbound';
426
- $sftpDumpFile->cd($processedDir);
427
- $files = $sftpDumpFile->ls();
428
-
429
- //Pb_Pbgsp_Model_Util::log($files);
430
-
431
- $exportedFiles = $this->_getLastExportedFileNames();
432
- if(!$exportedFiles)
433
- return;
434
- foreach($files as $file) {
435
- foreach($exportedFiles as $exportedFile) {
436
- $fileNameWithoutExtension = str_replace(".gpg","",str_replace(".csv","",$exportedFile));
437
- if($this->_startsWith($file['text'],$fileNameWithoutExtension)) {
438
- $dest = $notificationDir.'/'.$file['text'];
439
- $sftpDumpFile->read($file['text'],$dest);
440
- }
441
- }
442
-
443
- }
444
- $sftpDumpFile->close();
445
- }
446
- catch (Exception $e) {
447
- Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
448
- Pb_Pbgsp_Model_Util::log("Pb Module could not connect to sftp server: ".$credentials['host']." Wrong username/password. Postponing catalog upload.");
449
- return;
450
- }
451
-
452
- }
453
-
454
- private function _encryptExportedFiles($exportedFiles) {
455
- $encryptedFiles = array();
456
- $publicKey = Pb_Pbgsp_Model_Credentials::getPublicKey();
457
- if(!isset($publicKey) || $publicKey=='') {
458
- Pb_Pbgsp_Model_Util::log('Public key is not set cannot encrypt catalog files.');
459
- return $exportedFiles;
460
- }
461
- try {
462
- $gnupg = new gnupg();
463
- $keyInfo = $gnupg->import($publicKey);
464
- $gnupg->addencryptkey($keyInfo['fingerprint']);
465
- $tmpDir = $this->_getTempDir();
466
- Pb_Pbgsp_Model_Util::log('Encrypting the files.');
467
- foreach($exportedFiles as $exportedFile) {
468
- $fileName = $tmpDir . $exportedFile;
469
- if(is_dir($fileName))
470
- continue;
471
- $encryptedFileName = $exportedFile.'.gpg';
472
- Pb_Pbgsp_Model_Util::log("Encrypted file $encryptedFileName");
473
- file_put_contents($tmpDir.$encryptedFileName,$gnupg->encrypt(file_get_contents($fileName)));
474
- $encryptedFiles[] = $encryptedFileName;
475
- }
476
- return $encryptedFiles;
477
- }
478
- catch (Exception $e) {
479
- Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
480
- Pb_Pbgsp_Model_Util::log("Error in encryption.");
481
- return $encryptedFiles;
482
- }
483
-
484
-
485
- }
486
- public function upload() {
487
-
488
- $tmpDir = $this->_getTempDir();
489
- $exportedFiles = array_diff(scandir($tmpDir), array('..', '.'));
490
- if (count($this->productIds) == 0) {
491
- // No new products to send, don't send anything.
492
- $this->_removeExportedFiles($exportedFiles);
493
-
494
- return;
495
- }
496
-
497
- Pb_Pbgsp_Model_Util::log("Pb catalog file upload started");
498
- try {
499
-
500
- if(Pb_Pbgsp_Model_Credentials::isEncryptionEnabled()) {
501
- $exportedFiles = $this->_encryptExportedFiles($exportedFiles);
502
- }
503
- else {
504
- Pb_Pbgsp_Model_Util::log('Encryption is not enabled.'.Pb_Pbgsp_Model_Credentials::isEncryptionEnabled());
505
- }
506
- $sftpDumpFile = new Varien_Io_Sftp();
507
- $credentials = $this->_getSftpCredentials();
508
-
509
- Pb_Pbgsp_Model_Util::log($credentials);
510
-
511
- $sftpDumpFile->open(
512
- $credentials
513
- );
514
- //Upload to SFTP
515
- $rootDir = Pb_Pbgsp_Model_Credentials::getSftpCatalogDirectory();
516
- if(!$this->_endsWith($rootDir,'/'))
517
- $rootDir = $rootDir.'/';
518
- $tmpSFTPDir = $rootDir.'tmp';
519
- $inboundDir = $rootDir.'inbound';
520
- $uploadedFiles = array();
521
- foreach($exportedFiles as $exportedFile) {
522
- $fileName = $tmpDir . $exportedFile;
523
- if(is_dir($fileName))
524
- continue;
525
-
526
- Pb_Pbgsp_Model_Util::log("CD to $tmpSFTPDir");
527
- $sftpDumpFile->cd($tmpSFTPDir);
528
- Pb_Pbgsp_Model_Util::log("Uploading $fileName");
529
- $sftpDumpFile->write($exportedFile, file_get_contents($fileName));
530
- Pb_Pbgsp_Model_Util::log("Moving ".$tmpSFTPDir."/$exportedFile"." to ".$inboundDir."/$exportedFile");
531
- $sftpDumpFile->mv($tmpSFTPDir."/$exportedFile",$inboundDir."/$exportedFile");
532
- $uploadedFiles[] = $exportedFile;
533
- }
534
- $sftpDumpFile->close();
535
-
536
- } catch (Exception $e) {
537
- Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
538
- Pb_Pbgsp_Model_Util::log("Pb Module could not connect to sftp server: ".$credentials['host']." Wrong username/password. Postponing catalog upload.");
539
- return;
540
- }
541
-
542
- Pb_Pbgsp_Model_Util::log("Pb catalog file upload ended");
543
-
544
- $this->_removeExportedFiles($exportedFiles);
545
- $this->updateLastProductUpload();
546
- $this->_logExportedFileInDB($uploadedFiles);
547
- }
548
-
549
- private function _getExportedFilesVariable() {
550
- $collection = Mage::getModel("pb_pbgsp/variable")->getCollection();
551
- $exportedFilesVariable = null;
552
- foreach ($collection as $variable) {
553
-
554
- if ($variable->getName() == "exportedFiles") {
555
- $exportedFilesVariable = $variable;
556
- break;
557
- }
558
-
559
- }
560
- return $exportedFilesVariable;
561
- }
562
- private function _getLastExportedFileNames() {
563
- $exportedFilesVariable = $this->_getExportedFilesVariable();
564
- if(!isset($exportedFilesVariable))
565
- return false;
566
- $exportedFiles = explode('|',$exportedFilesVariable->getValue());
567
- return $exportedFiles;
568
- }
569
- private function _logExportedFileInDB($exportedFiles) {
570
- $strExportedFiles = implode('|',$exportedFiles);
571
- $exportedFilesVariable = $this->_getExportedFilesVariable();
572
- if(!isset($exportedFilesVariable))
573
- {
574
- $exportedFilesVariable = Mage::getModel("pb_pbgsp/variable");
575
- $exportedFilesVariable->setName("exportedFiles");
576
- }
577
-
578
- $exportedFilesVariable->setValue($strExportedFiles);
579
- $exportedFilesVariable->save();
580
- }
581
- private function _startsWith($haystack, $needle) {
582
- // search backwards starting from haystack length characters from the end
583
- return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
584
- }
585
- private function _endsWith($haystack, $needle) {
586
- // search forward starting from end minus needle length characters
587
- return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
588
- }
589
- private function _removeExportedFiles($exportedFiles) {
590
- $tmpDir = $this->_getTempDir();
591
- foreach($exportedFiles as $exportedFile) {
592
- $fileName = $tmpDir . $exportedFile;
593
- if(is_dir($fileName))
594
- continue;
595
- unlink($fileName);
596
- $fileName = str_replace(".gpg","",$fileName);//remove unencrypted file
597
- if(is_file($fileName))
598
- unlink($fileName);
599
- }
600
- }
601
-
602
-
603
-
604
-
605
-
606
-
607
- /**
608
- * @param Pb_Pbgsp_Model_Catalog_Product $product
609
- * @param string $categoryCode
610
- */
611
- private function writeProduct($product,$categoryCode,$parentSku,$category)
612
- {
613
- if ($product->shouldUpload($this->lastDiff)) {
614
- array_push($this->productIds,$product->getMageProduct()->getId());
615
- // Pb_Pbgsp_Model_Util::log("Product SKU:" . $product->getSKU());
616
- $product->writeToFile($this->file,$categoryCode,$parentSku,$category);
617
- fflush($this->file);
618
- }
619
- }
620
-
621
- public static function stripHtml($text) {
622
- return preg_replace("/<\s*\/\s*\w\s*.*?>|<\s*br\s*>/",'',preg_replace("/<\s*\w.*?>/", '', $text));
623
- }
624
-
625
- /**
626
- * Loads products without categories and logs them in log file
627
- */
628
- public function logProdWithoutCategories() {
629
- $productCollection = Mage::getResourceModel('catalog/product_collection')
630
- ->setStoreId(0)
631
- ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
632
- ->addAttributeToFilter('category_id', array('null' => true))
633
- ->addAttributeToSelect('*');
634
-
635
-
636
- $productCollection->getSelect()->group('product_id')->distinct(true);
637
-
638
- $productCollection->load();
639
- $skus = '';
640
- foreach($productCollection as $product) {
641
- $skus = $skus . $product->getSku() . ",";
642
-
643
- }
644
- Pb_Pbgsp_Model_Util::log("Products without categories:" . $skus);
645
- }
646
-
647
- /**
648
- * @return array
649
- */
650
- private function _getSftpCredentials()
651
- {
652
- $credentials = array(
653
- 'host' => Pb_Pbgsp_Model_Credentials::getSftpHostname(),
654
- "port" => Pb_Pbgsp_Model_Credentials::getSftpPort(),
655
- 'username' => Pb_Pbgsp_Model_Credentials::getSftpUsername(),
656
- 'password' => Pb_Pbgsp_Model_Credentials::getSftpPassword(),
657
- 'timeout' => '10'
658
- );
659
- return $credentials;
660
- }
661
-
662
- /**
663
- * @param $part
664
- */
665
- private function _stripPartFromFileName($part)
666
- {
667
- if ($part == 2) {
668
- //there is only one part remove part1 from filename
669
- rename($this->filename, str_replace('_part1', '', $this->filename));
670
- }
671
- }
672
- }
673
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Model/Catalog/File.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+
11
+ class Pb_Pbgsp_Model_Catalog_File {
12
+
13
+
14
+ private $file;
15
+ private $filename;
16
+ private $lastDiff;
17
+ private $productIds;
18
+ private $lastFileName;
19
+ private $uploadedCategories;
20
+ public function __construct($lastDiff = false) {
21
+ $this->lastDiff = $lastDiff;
22
+ $this->productIds = array();
23
+ $this->uploadedCategories = array();
24
+ }
25
+
26
+ private function _getTempDir() {
27
+ $appRoot = Mage::getRoot();
28
+ $mageRoot = dirname($appRoot);
29
+ $configOptions = Mage::getModel('core/config_options');
30
+ $tmpDir = $mageRoot . '/var/pbgsp/tmp/';
31
+ $configOptions->createDirIfNotExists( $tmpDir);
32
+ chmod($tmpDir, 0777);
33
+ return $tmpDir;
34
+ }
35
+
36
+
37
+ private function _getDataFileName($dataFeedName,$part=null) {
38
+ $partName = '';
39
+ if($part)
40
+ $partName = '_part'.$part;
41
+ $fileName = Pb_Pbgsp_Model_Credentials::getCatalogSenderID() . "_".$dataFeedName."_update_". Pb_Pbgsp_Model_Credentials::getPBID().'_'.date('Ymd_His').'_'.mt_rand(100000, 999999);
42
+ if($part == 1)
43
+ $this->lastFileName = $fileName;
44
+ else
45
+ $fileName = $this->lastFileName;
46
+ return $fileName.$partName.'.csv';
47
+ }
48
+ private function _createNewCommoditiyFile($part=null) {
49
+ $fileName = $this->_getDataFileName('catalog',$part);
50
+
51
+
52
+ $this->filename = $this->_getTempDir().$fileName;
53
+ $this->file = fopen($this->filename,"w+");
54
+ chmod($this->filename, 0777);
55
+ //add header row
56
+ fputcsv($this->file,array('MERCHANT_COMMODITY_REF_ID','COMMODITY_NAME_TITLE','SHORT_DESCRIPTION',
57
+ 'LONG_DESCRIPTION','RETAILER_ID','COMMODITY_URL','RETAILER_UNIQUE_ID','PCH_CATEGORY_ID',
58
+ 'RH_CATEGORY_ID','STANDARD_PRICE','WEIGHT_UNIT','DISTANCE_UNIT','COO','IMAGE_URL','PARENT_SKU',
59
+ 'CHILD_SKU','PARCELS_PER_SKU','UPC','UPC_CHECK_DIGIT','GTIN','MPN','ISBN','BRAND','MANUFACTURER',
60
+ 'MODEL_NUMBER','MANUFACTURER_STOCK_NUMBER','COMMODITY_CONDITION','COMMODITY_HEIGHT',
61
+ 'COMMODITY_WIDTH','COMMODITY_LENGTH','PACKAGE_WEIGHT','PACKAGE_HEIGHT','PACKAGE_WIDTH',
62
+ 'PACKAGE_LENGTH','HAZMAT','ORMD','CHEMICAL_INDICATOR','PESTICIDE_INDICATOR','AEROSOL_INDICATOR',
63
+ 'RPPC_INDICATOR','BATTERY_TYPE','NON_SPILLABLE_BATTERY','FUEL_RESTRICTION','SHIP_ALONE',
64
+ 'RH_CATEGORY_ID_PATH','RH_CATEGORY_NAME_PATH'));//,'RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT','HS_CODE','CURRENCY'
65
+
66
+ fflush($this->file);
67
+ }
68
+ private function _createNewCategoryFile($part=null) {
69
+ $fileName = $this->_getDataFileName('category-tree',$part);
70
+
71
+
72
+ $this->filename = $this->_getTempDir().$fileName;
73
+ $this->file = fopen($this->filename,"w+");
74
+ chmod($this->filename, 0777);
75
+ //add header row
76
+ fputcsv($this->file,array('CATEGORY_ID','PARENT_CATEGORY_ID','NAME',
77
+ 'ID_PATH','URL'));
78
+
79
+ fflush($this->file);
80
+ }
81
+
82
+
83
+
84
+
85
+ private function _getSelectedCategory($categories,$catId) {
86
+ foreach($categories as $cat) {
87
+ if($cat->getId() == $catId)
88
+ return $cat;
89
+ }
90
+ return false;
91
+ }
92
+ /**
93
+ * Extracts the categories and products and exports them into xml file.
94
+ */
95
+ public function createNew() {
96
+
97
+ $maxRecordsCount = Pb_Pbgsp_Model_Credentials::getMaxRecordsCount();
98
+ if(!$maxRecordsCount)
99
+ $maxRecordsCount = 10000;
100
+
101
+ $prodCount = 0;
102
+ $catCount = 0;
103
+ $fileRecordCount = 0;
104
+ //get stores which has disabled clearpath
105
+ $stores = Mage::app()->getStores();
106
+ $defaultStoreUrl = Mage::getBaseUrl();
107
+ $secDefaultStoreUrl = str_replace("http","https",$defaultStoreUrl);
108
+ $disabledStores = array();
109
+ $addedCategories = array();
110
+ $part=1;
111
+ foreach($stores as $store) {
112
+
113
+ $isActive = Mage::getStoreConfig('carriers/pbgsp/active',$store);
114
+ $baseURL = $store->getBaseUrl();
115
+
116
+ if(!$isActive) {
117
+ $disabledStores[] = $store;
118
+ Pb_Pbgsp_Model_Util::log("Disabled store". $store->getId(). ' '. $store->getCode());
119
+ }
120
+ else {
121
+ $rootId = Mage::app()->getStore($store->getId())->getRootCategoryId();
122
+ $rootCat = Mage::getModel('catalog/category')->load($rootId);
123
+ /* @var $rootCat Mage_Catalog_Model_Category */
124
+ $rootCat->setData('store',$store);
125
+ Pb_Pbgsp_Model_Util::log("Default store url $defaultStoreUrl store ".$store->getCode()." store base url".
126
+ $baseURL." root cat url". $rootCat->getUrl(). " cat name". $rootCat->getName());
127
+ $catUrl = str_replace($defaultStoreUrl,$baseURL,$rootCat->getUrl());
128
+ if($catUrl == $rootCat->getUrl())
129
+ $catUrl = str_replace($secDefaultStoreUrl,$baseURL,$rootCat->getUrl());
130
+ $cat = new Pb_Pbgsp_Model_Catalog_Category($rootCat,$catUrl);
131
+ if(!$this->file || $fileRecordCount > $maxRecordsCount)
132
+ {
133
+ $this->_createNewCategoryFile($part);
134
+ $fileRecordCount=0;
135
+ $part++;
136
+ }
137
+ if($cat->writeToFile($this->file,$this->lastDiff))
138
+ $this->uploadedCategories[] = $rootCat;
139
+ fflush($this->file);
140
+ $catCount++;
141
+ $fileRecordCount++;
142
+ $categories = Mage::getModel('catalog/category')
143
+ ->getCollection()
144
+ ->addUrlRewriteToResult()
145
+ ->addAttributeToSelect('name')
146
+ ->addAttributeToSelect('pb_pbgsp_upload_active')
147
+ ->addAttributeToSelect('pb_pbgsp_upload')
148
+ ->addFieldToFilter('path', array('like'=> "1/$rootId/%"));
149
+ $addedCategories[] = $rootCat;
150
+
151
+ foreach($categories as $category) {
152
+ if(!$this->file || $fileRecordCount > $maxRecordsCount)
153
+ {
154
+ $this->_createNewCategoryFile($part);
155
+ $fileRecordCount=0;
156
+ $part++;
157
+ }
158
+ /* @var $category Mage_Catalog_Model_Category */
159
+ $category->setStoreId($store->getId());
160
+ $category->setData('store',$store);
161
+ $addedCategories[] = $category;
162
+
163
+
164
+
165
+
166
+ $catUrl = str_replace($defaultStoreUrl,$baseURL,$category->getUrl());
167
+ if($catUrl == $category->getUrl())
168
+ $catUrl = str_replace($secDefaultStoreUrl,$baseURL,$category->getUrl());
169
+ $cat = new Pb_Pbgsp_Model_Catalog_Category($category,$catUrl);
170
+ if($cat->writeToFile($this->file,$this->lastDiff))
171
+ $this->uploadedCategories[] = $category;
172
+ fflush($this->file);
173
+ $catCount++;
174
+ $fileRecordCount++;
175
+ }
176
+ }
177
+ }
178
+
179
+ fclose($this->file);
180
+ $this->_stripPartFromFileName($part);
181
+ //fwrite($this->file,"</CategoryList>\n<CommodityList>\n");
182
+ $fileRecordCount=0;
183
+ $part=1;
184
+ $this->_createNewCommoditiyFile($part);
185
+ $part++;
186
+ $addedProducts = array();
187
+ foreach($addedCategories as $category) {
188
+ //Mage::app()->setCurrentStore($category->getStoreId());
189
+
190
+ $count = Mage::getModel('catalog/product')->getCollection()
191
+ ->addCategoryFilter($category)
192
+ ->count();
193
+ $pageSize = 400;
194
+ $currIndex = 0;
195
+ while($currIndex < $count) {
196
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
197
+
198
+ ->addCategoryFilter($category)
199
+
200
+ ->addAttributeToSelect('name')
201
+ ->addAttributeToSelect('sku')
202
+ ->addAttributeToSelect('country_of_manufacture')
203
+ ->addAttributeToSelect('description')
204
+ ->addAttributeToSelect('product_url')
205
+ ->addAttributeToSelect('type_id')
206
+ ->addAttributeToSelect('pb_pbgsp_upload')
207
+ // ->addUrlRewrite($category->getId()) //this will add the url rewrite.
208
+ ->addAttributeToSelect('price')
209
+ ->addAttributeToSelect('weight');
210
+
211
+ $baseURL = Mage::app()->getStore($category->getStoreId())->getBaseUrl();
212
+ $productUrlFormat = $baseURL ."catalog/product/view/id/%d/";
213
+ foreach($productCollection as $product) {
214
+ /* @var $product Mage_Catalog_Model_Product */
215
+ if($product->getTypeId() == 'virtual')
216
+ continue;
217
+ $cateIds = $product->getCategoryIds();
218
+ $cateId = 0;
219
+ foreach($cateIds as $cId) {
220
+ $cateId = $cId;//get lower level of category
221
+ }
222
+ $prodCat = $this->_getSelectedCategory($addedCategories,$cateId);
223
+ if(!$prodCat)
224
+ $prodCat = $category;
225
+ $cIds = explode('/',$prodCat->getPath());
226
+ $cIds = array_slice($cIds,1);//remove root category
227
+ $prodCat->setData('id_path',implode(':',$cIds));
228
+ $prodCat->setData('name_path',$this->_getCatNamePath($addedCategories,$cIds));
229
+ if($product->getTypeId() == 'configurable' ) {
230
+ $productType = $product->getTypeInstance(true);
231
+ $allowedProducts = $productType->getUsedProducts(null, $product);
232
+ /** @var $childProduct Mage_Catalog_Model_Product */
233
+
234
+ foreach($allowedProducts as $childProduct) {
235
+ if(!array_key_exists($childProduct->getSku(),$addedProducts)) {
236
+ if( $fileRecordCount > $maxRecordsCount)
237
+ {
238
+ $this->_createNewCommoditiyFile($part);
239
+ $fileRecordCount=0;
240
+ $part++;
241
+ }
242
+ $pbChildProduct = new Pb_Pbgsp_Model_Catalog_Product($childProduct->getId(),sprintf($productUrlFormat,$product->getId()));
243
+ $this->writeProduct($pbChildProduct,$cateId,$product->getSku(),$prodCat);
244
+ $addedProducts[$childProduct->getSku()] = "added";
245
+ $prodCount++;
246
+ $fileRecordCount++;
247
+ }
248
+ }
249
+ }
250
+ else {
251
+ if(!array_key_exists($product->getSku(),$addedProducts)) {
252
+ $pbProduct = new Pb_Pbgsp_Model_Catalog_Product($product,sprintf($productUrlFormat,$product->getId()));
253
+ if( $fileRecordCount > $maxRecordsCount)
254
+ {
255
+ $this->_createNewCommoditiyFile();
256
+ $fileRecordCount=0;
257
+ $part++;
258
+ }
259
+ $this->writeProduct($pbProduct,$cateId,null,$prodCat);
260
+ $prodCount++;
261
+ $fileRecordCount++;
262
+ $addedProducts[$product->getSku()] = "added";
263
+
264
+ }
265
+
266
+
267
+ }
268
+
269
+
270
+ }
271
+ $currIndex += $pageSize;
272
+
273
+ }
274
+ }
275
+
276
+
277
+
278
+ // fwrite($this->file,"</CommodityList>\n</Catalog>\n");
279
+ fflush($this->file);
280
+
281
+ $this->_stripPartFromFileName($part);
282
+ }
283
+
284
+ private function _getCatNamePath($categories,$cateIds) {
285
+
286
+ $names = array();
287
+ foreach($cateIds as $id) {
288
+ foreach($categories as $cat) {
289
+ if($cat->getId() == $id) {
290
+ array_push($names, $cat->getName());
291
+ break;
292
+ }
293
+ }
294
+ }
295
+ // Pb_Pbgsp_Model_Util::log($names);
296
+ return implode('|',$names);
297
+ }
298
+
299
+ /**
300
+ * Updates the pb_pbgsp_upload time in all uploaded products
301
+ */
302
+ public function updateLastProductUpload() {
303
+
304
+ $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'pb_pbgsp_upload');
305
+ if(!$attribute->getAttributeId()) {
306
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
307
+ $setup->addAttribute('catalog_product', 'pb_pbgsp_upload', array(
308
+ 'label' => 'Last Pb upload timestampt',
309
+ 'type' => 'datetime',
310
+ 'input' => 'datetime',
311
+ 'visible' => false,
312
+ 'required' => false,
313
+ 'position' => 1,
314
+ ));
315
+ }
316
+
317
+ $productIds = array_unique($this->productIds);
318
+ Pb_Pbgsp_Model_Util::log('Uploaded products' . count($productIds));
319
+ $updated = 0;
320
+ foreach ($productIds as $prodId) {
321
+ $product = Mage::getModel("catalog/product")->load($prodId);
322
+ //Pb_Pbgsp_Model_Util::log('Updating product '. $product->getSKU());
323
+ $product->unlockAttribute('pb_pbgsp_upload');
324
+ $product->setPbPbgspUpload(time());
325
+ try{
326
+ $product->save();
327
+ $updated++;
328
+ }catch(Exception $e){
329
+ Pb_Pbgsp_Model_Util::log("There was a problem saving the product with sku ". $product->getSku() ." Error Message \n" . $e->getMessage());
330
+ }
331
+
332
+ //Pb_Pbgsp_Model_Util::log($product->getId()." ".$product->getName()." ".$product->getPbPbgspUpload());
333
+ }
334
+ Pb_Pbgsp_Model_Util::log("$updated products' pb_pbgsp_upload updated");
335
+ }
336
+
337
+ public function updateLastCategoryUpload() {
338
+
339
+ $attribute = Mage::getModel('eav/config')->getAttribute('catalog_category', 'pb_pbgsp_upload');
340
+ if(!$attribute->getAttributeId()) {
341
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
342
+ $setup->addAttribute('catalog_category', 'pb_pbgsp_upload', array(
343
+ 'label' => 'Last Pb upload timestampt',
344
+ 'type' => 'datetime',
345
+ 'input' => 'datetime',
346
+ 'visible' => false,
347
+ 'required' => false,
348
+ 'position' => 1,
349
+ ));
350
+ }
351
+
352
+
353
+ Pb_Pbgsp_Model_Util::log('Uploaded categories' . count($this->uploadedCategories));
354
+ $updated = 0;
355
+ foreach ($this->uploadedCategories as $category) {
356
+ $category->unlockAttribute('pb_pbgsp_upload');
357
+ $category->setPbPbgspUpload(time());
358
+ try{
359
+ $category->save();
360
+ $updated++;
361
+ }catch(Exception $e){
362
+ Pb_Pbgsp_Model_Util::log("There was a problem saving the category ". $category->getName() ." Error Message \n" . $e->getMessage());
363
+ }
364
+
365
+ //Pb_Pbgsp_Model_Util::log($product->getId()." ".$product->getName()." ".$product->getPbPbgspUpload());
366
+ }
367
+ Pb_Pbgsp_Model_Util::log("$updated categories' pb_pbgsp_upload updated");
368
+ }
369
+
370
+ /**
371
+ * Uploads the xml file to clearpath SFTP server
372
+ */
373
+
374
+ private function _getNotificationDir() {
375
+ $tmpDir = $this->_getTempDir();
376
+ $configOptions = Mage::getModel('core/config_options');
377
+ $notificationDir = $tmpDir . 'notifications';
378
+ $configOptions->createDirIfNotExists( $notificationDir);
379
+ chmod($notificationDir, 0777);
380
+ return $notificationDir;
381
+ }
382
+
383
+ public function processStatusNotifications() {
384
+ try {
385
+
386
+ $adminEmail = Pb_Pbgsp_Model_Credentials::getAdminEmail();
387
+ if(!isset($adminEmail) || $adminEmail=='')
388
+ return;
389
+ $notificationDir = $this->_getNotificationDir();
390
+ $this->_downloadStatusNotifications($notificationDir);
391
+ $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
392
+ if(count($notificationFiles) > 0) {
393
+ $mail = new Zend_Mail();
394
+ $mail->setFrom('no-reply@pb.com','Pitney Bowes');
395
+ $mail->addTo($adminEmail)
396
+ ->setSubject('Catalog Export Error')
397
+ ->setBodyText('Catalog Export Error. Please see attached files.');
398
+ $fileCount = 0;
399
+ foreach($notificationFiles as $notificationFile) {
400
+ if($this->_endsWith($notificationFile,'.err') || $this->_endsWith($notificationFile,'.log') ) {
401
+ $file = $notificationDir.'/'. $notificationFile;
402
+ $at = new Zend_Mime_Part(file_get_contents($file));
403
+ $at->filename = basename($file);
404
+ $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
405
+ $at->encoding = Zend_Mime::ENCODING_8BIT;
406
+
407
+ $mail->addAttachment($at);
408
+ $fileCount++;
409
+ }
410
+
411
+ }
412
+ if($fileCount > 0) {
413
+ $mail->send();
414
+ Pb_Pbgsp_Model_Util::log("Email sent with error files.");
415
+ }
416
+
417
+ else {
418
+ Pb_Pbgsp_Model_Util::log(" No error files found.");
419
+ }
420
+ //keep these files until next upload and delete files from old upload
421
+ $this->_cleanNotificationFiles();
422
+ }
423
+ }
424
+ catch (Exception $e) {
425
+ Pb_Pbgsp_Model_Util::log("Error in processStatusNotifications:". $e->getMessage());
426
+ Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
427
+
428
+ }
429
+
430
+ }
431
+ private function _cleanNotificationFiles() {
432
+ //keep resent files until next upload and delete files from old upload
433
+ $lastExportedFiles = $this->_getLastExportedFileNames();
434
+ if(!$lastExportedFiles)
435
+ return;
436
+ $notificationDir = $this->_getNotificationDir();
437
+ $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
438
+
439
+ foreach($notificationFiles as $notificationFile) {
440
+ $path_parts = pathinfo($notificationFile);
441
+ $localFileNameWithoutExt = $path_parts['filename'];
442
+ $isOldFile = true;
443
+ foreach($lastExportedFiles as $lastExportedFile) {
444
+ $lastExportedFileNameWithoutExt = str_replace('.gpg','',str_replace('.csv','',$lastExportedFile));
445
+ if($lastExportedFileNameWithoutExt == $localFileNameWithoutExt) {
446
+ $isOldFile = false;
447
+ break;
448
+ }
449
+ }
450
+ if($isOldFile) {
451
+ //this is from 2nd last upload, remove it from disk
452
+ unlink($notificationDir.'/'.$notificationFile);
453
+ }
454
+ }
455
+
456
+ $exportedFilesVariable = $this->_getExportedFilesVariable();
457
+ if(!isset($exportedFilesVariable))
458
+ {
459
+ $exportedFilesVariable = Mage::getModel("pb_pbgsp/variable");
460
+ $exportedFilesVariable->setName("exportedFiles");
461
+ }
462
+
463
+ $exportedFilesVariable->setValue('');
464
+ $exportedFilesVariable->save();
465
+ }
466
+ private function _downloadStatusNotifications($notificationDir) {
467
+
468
+ $credentials = $this->_getSftpCredentials();
469
+ try {
470
+ $sftpDumpFile = new Varien_Io_Sftp();
471
+ $sftpDumpFile->open(
472
+ $credentials
473
+ );
474
+ $rootDir = Pb_Pbgsp_Model_Credentials::getSftpCatalogDirectory();
475
+ if(!$this->_endsWith($rootDir,'/'))
476
+ $rootDir = $rootDir.'/';
477
+ $processedDir = $rootDir.'outbound';
478
+ $sftpDumpFile->cd($processedDir);
479
+ $files = $sftpDumpFile->ls();
480
+
481
+ //Pb_Pbgsp_Model_Util::log($files);
482
+
483
+ $exportedFiles = $this->_getLastExportedFileNames();
484
+ if(!$exportedFiles)
485
+ return;
486
+ foreach($files as $file) {
487
+ foreach($exportedFiles as $exportedFile) {
488
+ if($exportedFile == '')
489
+ continue;
490
+ $fileNameWithoutExtension = str_replace(".gpg","",str_replace(".csv","",$exportedFile));
491
+ if($this->_startsWith($file['text'],$fileNameWithoutExtension)) {
492
+ $dest = $notificationDir.'/'.$file['text'];
493
+ $sftpDumpFile->read($file['text'],$dest);
494
+ }
495
+ }
496
+
497
+ }
498
+ $sftpDumpFile->close();
499
+ }
500
+ catch (Exception $e) {
501
+ Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
502
+ Pb_Pbgsp_Model_Util::log("Pb Module could not connect to sftp server: ".$credentials['host']." Wrong username/password. Postponing catalog upload.");
503
+ return;
504
+ }
505
+
506
+ }
507
+
508
+ private function _encryptExportedFiles($exportedFiles) {
509
+ $encryptedFiles = array();
510
+ $publicKey = Pb_Pbgsp_Model_Credentials::getPublicKey();
511
+ if(!isset($publicKey) || $publicKey=='') {
512
+ Pb_Pbgsp_Model_Util::log('Public key is not set cannot encrypt catalog files.');
513
+ return $exportedFiles;
514
+ }
515
+ try {
516
+ $gnupg = new gnupg();
517
+ $keyInfo = $gnupg->import($publicKey);
518
+ $gnupg->addencryptkey($keyInfo['fingerprint']);
519
+ $tmpDir = $this->_getTempDir();
520
+ Pb_Pbgsp_Model_Util::log('Encrypting the files.');
521
+ foreach($exportedFiles as $exportedFile) {
522
+ $fileName = $tmpDir . $exportedFile;
523
+ if(is_dir($fileName))
524
+ continue;
525
+ $encryptedFileName = $exportedFile.'.gpg';
526
+ Pb_Pbgsp_Model_Util::log("Encrypted file $encryptedFileName");
527
+ file_put_contents($tmpDir.$encryptedFileName,$gnupg->encrypt(file_get_contents($fileName)));
528
+ $encryptedFiles[] = $encryptedFileName;
529
+ }
530
+ return $encryptedFiles;
531
+ }
532
+ catch (Exception $e) {
533
+ Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
534
+ Pb_Pbgsp_Model_Util::log("Error in encryption.");
535
+ return $encryptedFiles;
536
+ }
537
+
538
+
539
+ }
540
+ public function upload() {
541
+
542
+ $tmpDir = $this->_getTempDir();
543
+ $exportedFiles = array_diff(scandir($tmpDir), array('..', '.'));
544
+ if (count($this->productIds) == 0) {
545
+ // No new products to send, don't send anything.
546
+ $this->_removeExportedFiles($exportedFiles);
547
+
548
+ return;
549
+ }
550
+
551
+ Pb_Pbgsp_Model_Util::log("Pb catalog file upload started");
552
+ try {
553
+
554
+ if(Pb_Pbgsp_Model_Credentials::isEncryptionEnabled()) {
555
+ $exportedFiles = $this->_encryptExportedFiles($exportedFiles);
556
+ }
557
+ else {
558
+ Pb_Pbgsp_Model_Util::log('Encryption is not enabled.'.Pb_Pbgsp_Model_Credentials::isEncryptionEnabled());
559
+ }
560
+ $sftpDumpFile = new Varien_Io_Sftp();
561
+ $credentials = $this->_getSftpCredentials();
562
+
563
+ Pb_Pbgsp_Model_Util::log($credentials);
564
+
565
+ $sftpDumpFile->open(
566
+ $credentials
567
+ );
568
+ //Upload to SFTP
569
+ $rootDir = Pb_Pbgsp_Model_Credentials::getSftpCatalogDirectory();
570
+ if(!$this->_endsWith($rootDir,'/'))
571
+ $rootDir = $rootDir.'/';
572
+ $tmpSFTPDir = $rootDir.'tmp';
573
+ $inboundDir = $rootDir.'inbound';
574
+ $uploadedFiles = array();
575
+ foreach($exportedFiles as $exportedFile) {
576
+ $fileName = $tmpDir . $exportedFile;
577
+ if(is_dir($fileName))
578
+ continue;
579
+
580
+ Pb_Pbgsp_Model_Util::log("CD to $tmpSFTPDir");
581
+ $sftpDumpFile->cd($tmpSFTPDir);
582
+ Pb_Pbgsp_Model_Util::log("Uploading $fileName");
583
+ $sftpDumpFile->write($exportedFile, file_get_contents($fileName));
584
+ Pb_Pbgsp_Model_Util::log("Moving ".$tmpSFTPDir."/$exportedFile"." to ".$inboundDir."/$exportedFile");
585
+ $sftpDumpFile->mv($tmpSFTPDir."/$exportedFile",$inboundDir."/$exportedFile");
586
+ $uploadedFiles[] = $exportedFile;
587
+ }
588
+ $sftpDumpFile->close();
589
+
590
+ } catch (Exception $e) {
591
+ Pb_Pbgsp_Model_Util::log($e->getTraceAsString());
592
+ Pb_Pbgsp_Model_Util::log("Pb Module could not connect to sftp server: ".$credentials['host']." Wrong username/password. Postponing catalog upload.");
593
+ return;
594
+ }
595
+
596
+ Pb_Pbgsp_Model_Util::log("Pb catalog file upload ended");
597
+
598
+ $this->_removeExportedFiles($exportedFiles);
599
+ $this->updateLastCategoryUpload();
600
+ $this->updateLastProductUpload();
601
+ $this->_logExportedFileInDB($uploadedFiles);
602
+ }
603
+
604
+ private function _getExportedFilesVariable() {
605
+ $collection = Mage::getModel("pb_pbgsp/variable")->getCollection();
606
+ $exportedFilesVariable = null;
607
+ foreach ($collection as $variable) {
608
+
609
+ if ($variable->getName() == "exportedFiles") {
610
+ $exportedFilesVariable = $variable;
611
+ break;
612
+ }
613
+
614
+ }
615
+ return $exportedFilesVariable;
616
+ }
617
+ private function _getLastExportedFileNames() {
618
+ $exportedFilesVariable = $this->_getExportedFilesVariable();
619
+ if(!isset($exportedFilesVariable) && $exportedFilesVariable->getValue() != '')
620
+ return false;
621
+ $exportedFiles = explode('|',$exportedFilesVariable->getValue());
622
+ return $exportedFiles;
623
+ }
624
+ private function _logExportedFileInDB($exportedFiles) {
625
+ $strExportedFiles = implode('|',$exportedFiles);
626
+ $exportedFilesVariable = $this->_getExportedFilesVariable();
627
+ if(!isset($exportedFilesVariable))
628
+ {
629
+ $exportedFilesVariable = Mage::getModel("pb_pbgsp/variable");
630
+ $exportedFilesVariable->setName("exportedFiles");
631
+ }
632
+
633
+ $exportedFilesVariable->setValue($strExportedFiles);
634
+ $exportedFilesVariable->save();
635
+ }
636
+ private function _startsWith($haystack, $needle) {
637
+ // search backwards starting from haystack length characters from the end
638
+ return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
639
+ }
640
+ private function _endsWith($haystack, $needle) {
641
+ // search forward starting from end minus needle length characters
642
+ return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
643
+ }
644
+ private function _removeExportedFiles($exportedFiles) {
645
+ $tmpDir = $this->_getTempDir();
646
+ foreach($exportedFiles as $exportedFile) {
647
+ $fileName = $tmpDir . $exportedFile;
648
+ if(is_dir($fileName))
649
+ continue;
650
+ unlink($fileName);
651
+ $fileName = str_replace(".gpg","",$fileName);//remove unencrypted file
652
+ if(is_file($fileName))
653
+ unlink($fileName);
654
+ }
655
+ }
656
+
657
+
658
+
659
+
660
+
661
+
662
+ /**
663
+ * @param Pb_Pbgsp_Model_Catalog_Product $product
664
+ * @param string $categoryCode
665
+ */
666
+ private function writeProduct($product,$categoryCode,$parentSku,$category)
667
+ {
668
+ if ($product->shouldUpload($this->lastDiff)) {
669
+ array_push($this->productIds,$product->getMageProduct()->getId());
670
+ // Pb_Pbgsp_Model_Util::log("Product SKU:" . $product->getSKU());
671
+ $product->writeToFile($this->file,$categoryCode,$parentSku,$category);
672
+ fflush($this->file);
673
+ }
674
+ }
675
+
676
+ public static function stripHtml($text) {
677
+ return preg_replace("/<\s*\/\s*\w\s*.*?>|<\s*br\s*>/",'',preg_replace("/<\s*\w.*?>/", '', $text));
678
+ }
679
+
680
+ /**
681
+ * Loads products without categories and logs them in log file
682
+ */
683
+ public function logProdWithoutCategories() {
684
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
685
+ ->setStoreId(0)
686
+ ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
687
+ ->addAttributeToFilter('category_id', array('null' => true))
688
+ ->addAttributeToSelect('*');
689
+
690
+
691
+ $productCollection->getSelect()->group('product_id')->distinct(true);
692
+
693
+ $productCollection->load();
694
+ $skus = '';
695
+ foreach($productCollection as $product) {
696
+ $skus = $skus . $product->getSku() . ",";
697
+
698
+ }
699
+ Pb_Pbgsp_Model_Util::log("Products without categories:" . $skus);
700
+ }
701
+
702
+ /**
703
+ * @return array
704
+ */
705
+ private function _getSftpCredentials()
706
+ {
707
+ $credentials = array(
708
+ 'host' => Pb_Pbgsp_Model_Credentials::getSftpHostname(),
709
+ "port" => Pb_Pbgsp_Model_Credentials::getSftpPort(),
710
+ 'username' => Pb_Pbgsp_Model_Credentials::getSftpUsername(),
711
+ 'password' => Pb_Pbgsp_Model_Credentials::getSftpPassword(),
712
+ 'timeout' => '10'
713
+ );
714
+ return $credentials;
715
+ }
716
+
717
+ /**
718
+ * @param $part
719
+ */
720
+ private function _stripPartFromFileName($part)
721
+ {
722
+ if ($part == 2) {
723
+ //there is only one part remove part1 from filename
724
+ rename($this->filename, str_replace('_part1', '', $this->filename));
725
+ }
726
+ }
727
+ }
728
+ ?>
app/code/local/Pb/Pbgsp/Model/Catalog/Product.php CHANGED
@@ -1,198 +1,204 @@
1
- <?php
2
-
3
- /**
4
- * Class Pb_Pbgsp_Model_Catalog_Product
5
- *
6
- */
7
- class Pb_Pbgsp_Model_Catalog_Product {
8
- /*@var $product Mage_Catalog_Model_Product */
9
- protected $product;
10
- protected $_productUrl;
11
-
12
-
13
- public function __construct($product,$url=null) {
14
- $id = $product;
15
- if (gettype($product) == "object" && get_class($id) == "Mage_Catalog_Model_Product") {
16
- $this -> product = $product;
17
- }
18
- else
19
- $this -> product = Mage::getModel('catalog/product') -> load($id);
20
- $this->_productUrl = $url;
21
- }
22
-
23
- /**
24
- * Created by BigPixel 6/15/2012
25
- * @return Mage_Catalog_Model_Product
26
- */
27
- public function getMageProduct() {
28
- return $this->product;
29
- }
30
-
31
- /**
32
- * @return string
33
- */
34
- public function getSKU() {
35
- return $this -> product -> getSku();
36
- }
37
-
38
- public function getPrice() {
39
- return $this->product->getPrice();
40
- }
41
-
42
- public function getUPC() {
43
- }
44
-
45
- /**
46
- * @return string
47
- */
48
- public function getURL() {
49
- if($this->_productUrl)
50
- return $this->_productUrl;
51
- return $this -> product -> getProductUrl();
52
- }
53
-
54
- /**
55
- * @return int
56
- * Gets the id of the category that is direct parent of the product
57
- */
58
- public function getCategoryCode() {
59
- $categories = $this -> product -> getCategoryCollection();
60
-
61
- $maxDepth = -1;
62
- $finalCategory = null;
63
- foreach ($categories as $category) {
64
- $pathComponents = explode("/",$category->getPath());
65
- if (count($pathComponents) > $maxDepth) {
66
- $finalCategory = $category;
67
- $maxDepth = count($pathComponents);
68
- }
69
- }
70
- return $finalCategory->getId();
71
- }
72
-
73
- /**
74
- * @return string
75
- *
76
- */
77
- public function getCountryOfOrigin() {
78
- return $this->product->getCountryOfManufacture(); //added by kamran,1/14/2012
79
- }
80
-
81
- /**
82
- * @return string
83
- */
84
- public function getDescription() {
85
- return utf8_encode($this -> product -> getDescription());
86
- }
87
- public function getShortDescription() {
88
- return utf8_encode($this -> product -> getShortDescription());
89
- }
90
- /**
91
- * @return string
92
- */
93
- public function getName() {
94
- return utf8_encode($this -> product -> getName());
95
- }
96
-
97
- /**
98
- * @return flaot
99
- */
100
- public function getWeight() {
101
- return $this -> product -> getWeight();
102
- }
103
-
104
- public function getSize() {
105
- }
106
-
107
- /**
108
- * @param $file
109
- * @param $categoryCode
110
- * Write this product into the xml file
111
- */
112
- public function writeToFile($file,$categoryCode,$parentSku,$category) {
113
- /** $categoryCode is passed in method because we don't have categoryCode for child products. BigPixel 6/11/2012 */
114
- $name = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getName());
115
- $name = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
116
- $string = "<Commodity>\n";
117
- $string .= "<CategoryCode><![CDATA[" . htmlentities($categoryCode) . "]]></CategoryCode>\n";
118
- $string .= "<SKU><![CDATA[" . htmlentities($this -> getSKU()) . "]]></SKU>\n";
119
- $string .= "<Name><![CDATA[" . htmlentities($name) . "]]></Name>\n";
120
- $string .= "<CountryOfOrigin><![CDATA[" . htmlentities(preg_replace("/[^A-Za-z0-9]/",'',$this -> getCountryOfOrigin())) . "]]></CountryOfOrigin>\n"; //added by kamran,1/14/2012
121
- $description = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getDescription());
122
- $description = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $description);
123
- if (strlen($description) >= 2000) {
124
-
125
- $description = $this -> chopString($description, 1999);
126
- }
127
-
128
- $shortDescription = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getShortDescription());
129
- $shortDescription = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $shortDescription);
130
- if (strlen($shortDescription) >= 2000) {
131
-
132
- $shortDescription = $this -> chopString($shortDescription, 1999);
133
- }
134
- $string .= "<Description><![CDATA[" . $description . "]]></Description>\n";
135
- $string .= "<URL><![CDATA[" . htmlentities($this -> getURL()) . "]]></URL>\n";
136
-
137
- if ($this->getWeight() != null) {
138
- $string .= "<Size><Weight><![CDATA[" . $this -> getWeight() . "]]></Weight><Source><![CDATA[" . Pb_Pbgsp_Model_Credentials::getMerchantCode() . "]]></Source></Size>\n";
139
- }
140
- $string .= "</Commodity>\n";
141
- // fputcsv($this->file,array('MERCHANT_COMMODITY_REF_ID','COMMODITY_NAME_TITLE','SHORT_DESCRIPTION',
142
- // 'LONG_DESCRIPTION','RETAILER_ID','COMMODITY_URL','RETAILER_UNIQUE_ID','PCH_CATEGORY_ID',
143
- // 'RH_CATEGORY_ID','STANDARD_PRICE','WEIGHT_UNIT','DISTANCE_UNIT','COO','IMAGE_URL','PARENT_SKU',
144
- // 'CHILD_SKU','PARCELS_PER_SKU','UPC','UPC_CHECK_DIGIT','GTIN','MPN','ISBN','BRAND','MANUFACTURER',
145
- // 'MODEL_NUMBER','MANUFACTURER_STOCK_NUMBER','COMMODITY_CONDITION','COMMODITY_HEIGHT',
146
- // 'COMMODITY_WIDTH','COMMODITY_LENGTH','PACKAGE_WEIGHT','PACKAGE_HEIGHT','PACKAGE_WIDTH',
147
- // 'PACKAGE_LENGTH','HAZMAT','ORMD','CHEMICAL_INDICATOR','PESTICIDE_INDICATOR','AEROSOL_INDICATOR',
148
- // 'RPPC_INDICATOR','BATTERY_TYPE','NON_SPILLABLE_BATTERY','FUEL_RESTRICTION','SHIP_ALONE',
149
- // 'RH_CATEGORY_ID_PATH','RH_CATEGORY_NAME_PATH','RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT',
150
- // 'HS_CODE','CURRENCY'));
151
- $merchantCode = Pb_Pbgsp_Model_Credentials::getMerchantCode();
152
- fputcsv($file,array($this -> getSKU(),$name,$shortDescription,
153
- $description,$merchantCode,$this -> getURL(),$merchantCode,'',
154
- $categoryCode,$this->getPrice(),'lb','',$this->getCountryOfOrigin(),'','',
155
- '','','','','','','','','',
156
- '','','','',
157
- '','',$this -> getWeight(),'','',
158
- '','','','','','',
159
- '','','','','',
160
- strval($category->getData('id_path')),$category->getData('name_path')
161
- //,'','','','',$category->getData('store')->getCurrentCurrencyCode()
162
- ));
163
- //fwrite($file, $string);
164
- }
165
-
166
- /**
167
- * @param $lastDiff
168
- * @return bool
169
- * Checks whether we need to upload this product or not
170
- */
171
- public function shouldUpload($lastDiff) {
172
-
173
- $lastUpload = $this -> product -> getPbPbgspUpload();
174
- //Pb_Pbgsp_Model_Util::log('Product '. $this -> getSKU() . ' lastUpload='. $lastUpload . ' '. date('m-d-Y H:i:s',$lastUpload));
175
- if (!$lastUpload) {
176
- // First upload.
177
- return true;
178
- } else if ($lastDiff <= $lastUpload - (30 * 60)) {
179
- // Added after the last diff
180
- return true;
181
- } else {
182
- return false;
183
- }
184
- }
185
-
186
- public function chopString($str, $len) {
187
- $end = $len;
188
- $lastFour = substr($str,$end - strlen("&amp"),strlen("&amp"));
189
- $pos = strpos($lastFour,"&");
190
- if (!($pos === FALSE)) {
191
- $end = $end - strlen("&amp") + $pos;
192
- }
193
- $ret = substr($str,0,$end);
194
- return $ret;
195
- }
196
-
197
- }
198
- ?>
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Catalog/Product.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ /**
10
+ * Class Pb_Pbgsp_Model_Catalog_Product
11
+ *
12
+ */
13
+ class Pb_Pbgsp_Model_Catalog_Product {
14
+ /*@var $product Mage_Catalog_Model_Product */
15
+ protected $product;
16
+ protected $_productUrl;
17
+
18
+
19
+ public function __construct($product,$url=null) {
20
+ $id = $product;
21
+ if (gettype($product) == "object" && get_class($id) == "Mage_Catalog_Model_Product") {
22
+ $this -> product = $product;
23
+ }
24
+ else
25
+ $this -> product = Mage::getModel('catalog/product') -> load($id);
26
+ $this->_productUrl = $url;
27
+ }
28
+
29
+ /**
30
+ * Created by BigPixel 6/15/2012
31
+ * @return Mage_Catalog_Model_Product
32
+ */
33
+ public function getMageProduct() {
34
+ return $this->product;
35
+ }
36
+
37
+ /**
38
+ * @return string
39
+ */
40
+ public function getSKU() {
41
+ return $this -> product -> getSku();
42
+ }
43
+
44
+ public function getPrice() {
45
+ return $this->product->getPrice();
46
+ }
47
+
48
+ public function getUPC() {
49
+ }
50
+
51
+ /**
52
+ * @return string
53
+ */
54
+ public function getURL() {
55
+ if($this->_productUrl)
56
+ return $this->_productUrl;
57
+ return $this -> product -> getProductUrl();
58
+ }
59
+
60
+ /**
61
+ * @return int
62
+ * Gets the id of the category that is direct parent of the product
63
+ */
64
+ public function getCategoryCode() {
65
+ $categories = $this -> product -> getCategoryCollection();
66
+
67
+ $maxDepth = -1;
68
+ $finalCategory = null;
69
+ foreach ($categories as $category) {
70
+ $pathComponents = explode("/",$category->getPath());
71
+ if (count($pathComponents) > $maxDepth) {
72
+ $finalCategory = $category;
73
+ $maxDepth = count($pathComponents);
74
+ }
75
+ }
76
+ return $finalCategory->getId();
77
+ }
78
+
79
+ /**
80
+ * @return string
81
+ *
82
+ */
83
+ public function getCountryOfOrigin() {
84
+ return $this->product->getCountryOfManufacture(); //added by kamran,1/14/2012
85
+ }
86
+
87
+ /**
88
+ * @return string
89
+ */
90
+ public function getDescription() {
91
+ return utf8_encode($this -> product -> getDescription());
92
+ }
93
+ public function getShortDescription() {
94
+ return utf8_encode($this -> product -> getShortDescription());
95
+ }
96
+ /**
97
+ * @return string
98
+ */
99
+ public function getName() {
100
+ return utf8_encode($this -> product -> getName());
101
+ }
102
+
103
+ /**
104
+ * @return flaot
105
+ */
106
+ public function getWeight() {
107
+ return $this -> product -> getWeight();
108
+ }
109
+
110
+ public function getSize() {
111
+ }
112
+
113
+ /**
114
+ * @param $file
115
+ * @param $categoryCode
116
+ * Write this product into the xml file
117
+ */
118
+ public function writeToFile($file,$categoryCode,$parentSku,$category) {
119
+ /** $categoryCode is passed in method because we don't have categoryCode for child products. BigPixel 6/11/2012 */
120
+ $name = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getName());
121
+ $name = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
122
+ $string = "<Commodity>\n";
123
+ $string .= "<CategoryCode><![CDATA[" . htmlentities($categoryCode) . "]]></CategoryCode>\n";
124
+ $string .= "<SKU><![CDATA[" . htmlentities($this -> getSKU()) . "]]></SKU>\n";
125
+ $string .= "<Name><![CDATA[" . htmlentities($name) . "]]></Name>\n";
126
+ $string .= "<CountryOfOrigin><![CDATA[" . htmlentities(preg_replace("/[^A-Za-z0-9]/",'',$this -> getCountryOfOrigin())) . "]]></CountryOfOrigin>\n"; //added by kamran,1/14/2012
127
+ $description = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getDescription());
128
+ $description = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $description);
129
+ if (strlen($description) >= 2000) {
130
+
131
+ $description = $this -> chopString($description, 1999);
132
+ }
133
+
134
+ $shortDescription = Pb_Pbgsp_Model_Catalog_File::stripHtml($this -> getShortDescription());
135
+ $shortDescription = preg_replace("/[^A-Za-z0-9 ,.\-\+=;:\\(){}\[\]@?%$#]/", '', $shortDescription);
136
+ if (strlen($shortDescription) >= 2000) {
137
+
138
+ $shortDescription = $this -> chopString($shortDescription, 1999);
139
+ }
140
+ $string .= "<Description><![CDATA[" . $description . "]]></Description>\n";
141
+ $string .= "<URL><![CDATA[" . htmlentities($this -> getURL()) . "]]></URL>\n";
142
+
143
+ if ($this->getWeight() != null) {
144
+ $string .= "<Size><Weight><![CDATA[" . $this -> getWeight() . "]]></Weight><Source><![CDATA[" . Pb_Pbgsp_Model_Credentials::getMerchantCode() . "]]></Source></Size>\n";
145
+ }
146
+ $string .= "</Commodity>\n";
147
+ // fputcsv($this->file,array('MERCHANT_COMMODITY_REF_ID','COMMODITY_NAME_TITLE','SHORT_DESCRIPTION',
148
+ // 'LONG_DESCRIPTION','RETAILER_ID','COMMODITY_URL','RETAILER_UNIQUE_ID','PCH_CATEGORY_ID',
149
+ // 'RH_CATEGORY_ID','STANDARD_PRICE','WEIGHT_UNIT','DISTANCE_UNIT','COO','IMAGE_URL','PARENT_SKU',
150
+ // 'CHILD_SKU','PARCELS_PER_SKU','UPC','UPC_CHECK_DIGIT','GTIN','MPN','ISBN','BRAND','MANUFACTURER',
151
+ // 'MODEL_NUMBER','MANUFACTURER_STOCK_NUMBER','COMMODITY_CONDITION','COMMODITY_HEIGHT',
152
+ // 'COMMODITY_WIDTH','COMMODITY_LENGTH','PACKAGE_WEIGHT','PACKAGE_HEIGHT','PACKAGE_WIDTH',
153
+ // 'PACKAGE_LENGTH','HAZMAT','ORMD','CHEMICAL_INDICATOR','PESTICIDE_INDICATOR','AEROSOL_INDICATOR',
154
+ // 'RPPC_INDICATOR','BATTERY_TYPE','NON_SPILLABLE_BATTERY','FUEL_RESTRICTION','SHIP_ALONE',
155
+ // 'RH_CATEGORY_ID_PATH','RH_CATEGORY_NAME_PATH','RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT',
156
+ // 'HS_CODE','CURRENCY'));
157
+ $merchantCode = Pb_Pbgsp_Model_Credentials::getMerchantCode();
158
+ fputcsv($file,array($this -> getSKU(),$name,$shortDescription,
159
+ $description,$merchantCode,$this -> getURL(),$merchantCode,'',
160
+ $categoryCode,$this->getPrice(),'lb','',$this->getCountryOfOrigin(),'','',
161
+ '','','','','','','','','',
162
+ '','','','',
163
+ '','',$this -> getWeight(),'','',
164
+ '','','','','','',
165
+ '','','','','',
166
+ strval($category->getData('id_path')),$category->getData('name_path')
167
+ //,'','','','',$category->getData('store')->getCurrentCurrencyCode()
168
+ ));
169
+ //fwrite($file, $string);
170
+ }
171
+
172
+ /**
173
+ * @param $lastDiff
174
+ * @return bool
175
+ * Checks whether we need to upload this product or not
176
+ */
177
+ public function shouldUpload($lastDiff) {
178
+
179
+ $lastUpload = $this -> product -> getPbPbgspUpload();
180
+ //Pb_Pbgsp_Model_Util::log('Product '. $this -> getSKU() . ' lastUpload='. $lastUpload . ' '. date('m-d-Y H:i:s',$lastUpload));
181
+ if (!$lastUpload) {
182
+ // First upload.
183
+ return true;
184
+ } else if ($lastDiff <= $lastUpload - (30 * 60)) {
185
+ // Added after the last diff
186
+ return true;
187
+ } else {
188
+ return false;
189
+ }
190
+ }
191
+
192
+ public function chopString($str, $len) {
193
+ $end = $len;
194
+ $lastFour = substr($str,$end - strlen("&amp"),strlen("&amp"));
195
+ $pos = strpos($lastFour,"&");
196
+ if (!($pos === FALSE)) {
197
+ $end = $end - strlen("&amp") + $pos;
198
+ }
199
+ $ret = substr($str,0,$end);
200
+ return $ret;
201
+ }
202
+
203
+ }
204
+ ?>
app/code/local/Pb/Pbgsp/Model/Credentials.php CHANGED
@@ -1,114 +1,128 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Credentials {
3
-
4
- public static function decrypt($string) {
5
- if (!empty($string)) {
6
- return Mage::helper('core')->decrypt($string);
7
- }
8
- return "";
9
- }
10
-
11
- public static function getApiUrl() {
12
- return Mage::getStoreConfig('carriers/pbgsp/apiurl');
13
- }
14
- public static function getMaxRecordsCount() {
15
- return Mage::getStoreConfig('carriers/pbgsp/catalog_size');
16
- }
17
- public static function getAdminEmail() {
18
- return Mage::getStoreConfig('carriers/pbgsp/admin_email');
19
- }
20
- public static function getCatalogSenderID() {
21
- return Mage::getStoreConfig('carriers/pbgsp/catalog_sender_id');
22
- }
23
- public static function getDeliveryAdjustmentMinDays() {
24
- return self::_getIntValue(Mage::getStoreConfig('carriers/pbgsp/delivery_adjustment_min_days'));
25
- }
26
- public static function getDeliveryAdjustmentMaxDays() {
27
- return self::_getIntValue(Mage::getStoreConfig('carriers/pbgsp/delivery_adjustment_max_days'));
28
- }
29
- public static function getDomesticShippingFee() {
30
- return self::_getFloatValue(Mage::getStoreConfig('carriers/pbgsp/domestic_shipping_fee'));
31
- }
32
- public static function getDomesticShippingOption() {
33
- return Mage::getStoreConfig('carriers/pbgsp/domestic_shipping_option');
34
- }
35
- public static function isASNGenerationEnabled() {
36
- return Mage::getStoreConfig('carriers/pbgsp/asn_generation_enabled');
37
- }
38
- public static function getHandlingFee() {
39
-
40
- return self::_getFloatValue(Mage::getStoreConfig('carriers/pbgsp/handlingfee'));
41
- }
42
- private static function _getIntValue($value) {
43
- $number = 0;
44
-
45
- if(isset($value)) {
46
- if(is_numeric($value)) {
47
- $number = intval($value);
48
- }
49
- }
50
- return $number;
51
- }
52
- private static function _getFloatValue($value) {
53
- $number = 0;
54
-
55
- if(isset($value)) {
56
- if(is_numeric($value)) {
57
- $number = floatval($value);
58
- }
59
- }
60
- return $number;
61
- }
62
- public static function getHandlingOption() {
63
- return Mage::getStoreConfig('carriers/pbgsp/handlingoption');
64
- }
65
- /* public static function getWSDL() {
66
- if(Mage::getStoreConfig('carriers/pbgsp/environment') == 1) {
67
- // Production
68
- } else {
69
- // Staging
70
- return "./app/code/local/Pb/Pbgsp/etc/cpAPI.wsdl.xml";
71
- }
72
- }*/
73
-
74
- public static function getUsername() {
75
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/apiuser'));
76
- }
77
-
78
- public static function getPassword() {
79
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/apipass'));
80
- }
81
-
82
- public static function getMerchantCode() {
83
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/merchantcode'));
84
- }
85
-
86
- public static function getSftpUsername() {
87
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftpuser'));
88
- }
89
- public static function getSftpPassword() {
90
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftppass'));
91
- }
92
- public static function getSftpHostname() {
93
- return Mage::getStoreConfig('carriers/pbgsp/ftphost');
94
- }
95
- public static function getSftpPort() {
96
- return Mage::getStoreConfig('carriers/pbgsp/ftpport');
97
- }
98
- public static function getSftpCatalogDirectory() {
99
- return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftpdir'));
100
- }
101
- public static function isEncryptionEnabled() {
102
- return Mage::getStoreConfig('carriers/pbgsp/catalog_encryption_enabled');
103
- }
104
- public static function getPublicKey() {
105
- return Mage::getStoreConfig('carriers/pbgsp/encryption_public_key');
106
- }
107
- public static function getOrderMgmtAPIUrl() {
108
- return Mage::getStoreConfig('carriers/pbgsp/order_mgmt_api');
109
- }
110
- public static function getPBID() {
111
- return "16061";
112
- }
113
- }
114
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Credentials.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Credentials {
10
+
11
+ public static function decrypt($string) {
12
+ if (!empty($string)) {
13
+ return Mage::helper('core')->decrypt($string);
14
+ }
15
+ return "";
16
+ }
17
+
18
+ public static function getCheckoutUrl() {
19
+ return Mage::getStoreConfig('carriers/pbgsp/checkout_endpoint');
20
+ }
21
+ public static function getAuthorizationUrl() {
22
+ return Mage::getStoreConfig('carriers/pbgsp/authorization_endpoint');
23
+ }
24
+ public static function getOrderMgmtAPIUrl() {
25
+ return Mage::getStoreConfig('carriers/pbgsp/order_mgmt_api');
26
+ }
27
+ public static function getMaxRecordsCount() {
28
+ return Mage::getStoreConfig('carriers/pbgsp/catalog_size');
29
+ }
30
+ public static function getAdminEmail() {
31
+ return Mage::getStoreConfig('carriers/pbgsp/admin_email');
32
+ }
33
+ public static function getCatalogSenderID() {
34
+ return Mage::getStoreConfig('carriers/pbgsp/catalog_sender_id');
35
+ }
36
+ public static function getDeliveryAdjustmentMinDays() {
37
+ return self::_getIntValue(Mage::getStoreConfig('carriers/pbgsp/delivery_adjustment_min_days'));
38
+ }
39
+ public static function getDeliveryAdjustmentMaxDays() {
40
+ return self::_getIntValue(Mage::getStoreConfig('carriers/pbgsp/delivery_adjustment_max_days'));
41
+ }
42
+ public static function getDomesticShippingFee() {
43
+ return self::_getFloatValue(Mage::getStoreConfig('carriers/pbgsp/domestic_shipping_fee'));
44
+ }
45
+ public static function getDomesticShippingOption() {
46
+ return Mage::getStoreConfig('carriers/pbgsp/domestic_shipping_option');
47
+ }
48
+ public static function isASNGenerationEnabled() {
49
+ return Mage::getStoreConfig('carriers/pbgsp/asn_generation_enabled');
50
+ }
51
+ public static function isFreeTaxEnabled() {
52
+ return Mage::getStoreConfig('carriers/pbgsp/free_tax_enable');
53
+ }
54
+ public static function getHandlingFee() {
55
+
56
+ return self::_getFloatValue(Mage::getStoreConfig('carriers/pbgsp/handlingfee'));
57
+ }
58
+ private static function _getIntValue($value) {
59
+ $number = 0;
60
+
61
+ if(isset($value)) {
62
+ if(is_numeric($value)) {
63
+ $number = intval($value);
64
+ }
65
+ }
66
+ return $number;
67
+ }
68
+ private static function _getFloatValue($value) {
69
+ $number = 0;
70
+
71
+ if(isset($value)) {
72
+ if(is_numeric($value)) {
73
+ $number = floatval($value);
74
+ }
75
+ }
76
+ return $number;
77
+ }
78
+ public static function getHandlingOption() {
79
+ return Mage::getStoreConfig('carriers/pbgsp/handlingoption');
80
+ }
81
+ /* public static function getWSDL() {
82
+ if(Mage::getStoreConfig('carriers/pbgsp/environment') == 1) {
83
+ // Production
84
+ } else {
85
+ // Staging
86
+ return "./app/code/local/Pb/Pbgsp/etc/cpAPI.wsdl.xml";
87
+ }
88
+ }*/
89
+
90
+ public static function getUsername() {
91
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/apiuser'));
92
+ }
93
+
94
+ public static function getPassword() {
95
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/apipass'));
96
+ }
97
+
98
+ public static function getMerchantCode() {
99
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/merchantcode'));
100
+ }
101
+
102
+ public static function getSftpUsername() {
103
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftpuser'));
104
+ }
105
+ public static function getSftpPassword() {
106
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftppass'));
107
+ }
108
+ public static function getSftpHostname() {
109
+ return Mage::getStoreConfig('carriers/pbgsp/ftphost');
110
+ }
111
+ public static function getSftpPort() {
112
+ return Mage::getStoreConfig('carriers/pbgsp/ftpport');
113
+ }
114
+ public static function getSftpCatalogDirectory() {
115
+ return self::decrypt(Mage::getStoreConfig('carriers/pbgsp/ftpdir'));
116
+ }
117
+ public static function isEncryptionEnabled() {
118
+ return Mage::getStoreConfig('carriers/pbgsp/catalog_encryption_enabled');
119
+ }
120
+ public static function getPublicKey() {
121
+ return Mage::getStoreConfig('carriers/pbgsp/encryption_public_key');
122
+ }
123
+
124
+ public static function getPBID() {
125
+ return "16061";
126
+ }
127
+ }
128
+ ?>
app/code/local/Pb/Pbgsp/Model/Creditmemo/Duty.php CHANGED
@@ -1,31 +1,38 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Creditmemo_Duty extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
3
- {
4
- public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
5
- {
6
- Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Creditmemo_Duty.collect');
7
- $len = strlen("pbgsp_");
8
- $order = $creditmemo->getOrder();
9
- $shipMethod = $order->getShippingMethod();
10
- if (strlen($shipMethod) > $len && substr($shipMethod, 0, $len) == "pbgsp_") {
11
- $totalTax = 0;
12
- $baseTotalTax = 0;
13
- $totalHiddenTax = 0;
14
- $baseTotalHiddenTax = 0;
15
- if ($order->getTaxAmount()) {
16
- $totalTax = $order->getTaxAmount();
17
- $baseTotalTax = $totalTax;
18
- }
19
- $creditmemo->setTaxAmount($totalTax);
20
- $creditmemo->setBaseTaxAmount($baseTotalTax);
21
- $creditmemo->setHiddenTaxAmount($totalHiddenTax);
22
- $creditmemo->setBaseHiddenTaxAmount($baseTotalHiddenTax);
23
- $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax + $totalHiddenTax);
24
- $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax + $baseTotalHiddenTax);
25
- } else {
26
- parent::collect($creditmemo);
27
- }
28
-
29
- return $this;
30
- }
 
 
 
 
 
 
 
31
  }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Creditmemo/Duty.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Creditmemo_Duty extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
10
+ {
11
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
12
+ {
13
+ Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Creditmemo_Duty.collect');
14
+ $len = strlen("pbgsp_");
15
+ $order = $creditmemo->getOrder();
16
+ $shipMethod = $order->getShippingMethod();
17
+ if (strlen($shipMethod) > $len && substr($shipMethod, 0, $len) == "pbgsp_") {
18
+ $totalTax = 0;
19
+ $baseTotalTax = 0;
20
+ $totalHiddenTax = 0;
21
+ $baseTotalHiddenTax = 0;
22
+ if ($order->getTaxAmount()) {
23
+ $totalTax = $order->getTaxAmount();
24
+ $baseTotalTax = $totalTax;
25
+ }
26
+ $creditmemo->setTaxAmount($totalTax);
27
+ $creditmemo->setBaseTaxAmount($baseTotalTax);
28
+ $creditmemo->setHiddenTaxAmount($totalHiddenTax);
29
+ $creditmemo->setBaseHiddenTaxAmount($baseTotalHiddenTax);
30
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax + $totalHiddenTax);
31
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax + $baseTotalHiddenTax);
32
+ } else {
33
+ parent::collect($creditmemo);
34
+ }
35
+
36
+ return $this;
37
+ }
38
  }
app/code/local/Pb/Pbgsp/Model/Handlingoptions.php CHANGED
@@ -1,18 +1,18 @@
1
- <?php
2
- /**
3
- * Created by JetBrains PhpStorm.
4
- * User: muhammad.kamran
5
- * Date: 6/6/12
6
- * Time: 11:36 PM
7
- * To change this template use File | Settings | File Templates.
8
- */
9
- class Pb_Pbgsp_Model_Handlingoptions {
10
- public function toOptionArray()
11
- {
12
- return array(
13
- array('value'=>1, 'label'=>'Per Order'),
14
- array('value'=>2, 'label'=>'Per Item'),
15
-
16
- );
17
- }
18
  }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Handlingoptions.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Handlingoptions {
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value'=>1, 'label'=>'Per Order'),
14
+ array('value'=>2, 'label'=>'Per Item'),
15
+
16
+ );
17
+ }
18
  }
app/code/local/Pb/Pbgsp/Model/Helper.php CHANGED
@@ -1,11 +1,18 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Helper {
3
- public static function displayInfo($var) {
4
- echo "<hr/>Class type: ".get_class($var)."<br/>Methods:<br/>";
5
- $methods = get_class_methods($var);
6
- foreach ($methods as $method) {
7
- echo $method."<br/>";
8
- }
9
- }
10
- }
11
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Helper.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Helper {
10
+ public static function displayInfo($var) {
11
+ echo "<hr/>Class type: ".get_class($var)."<br/>Methods:<br/>";
12
+ $methods = get_class_methods($var);
13
+ foreach ($methods as $method) {
14
+ echo $method."<br/>";
15
+ }
16
+ }
17
+ }
18
+ ?>
app/code/local/Pb/Pbgsp/Model/Inboundparcel.php CHANGED
@@ -1,11 +1,17 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Inboundparcel extends Mage_Core_Model_Abstract {
4
- public function _construct()
5
- {
6
- parent::_construct();
7
- $this->_init('pb_pbgsp/inboundparcel');
8
- }
9
- }
10
-
11
- ?>
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Inboundparcel.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Inboundparcel extends Mage_Core_Model_Abstract {
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('pb_pbgsp/inboundparcel');
14
+ }
15
+ }
16
+
17
+ ?>
app/code/local/Pb/Pbgsp/Model/Invoice/Duty.php CHANGED
@@ -1,32 +1,40 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Invoice_Duty extends Mage_Sales_Model_Order_Invoice_Total_Tax
3
- {
4
- public function collect(Mage_Sales_Model_Order_Invoice $invoice)
5
- {
6
- Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Invoice_Duty.collect');
7
- $len = strlen("pbgsp_");
8
- $order = $invoice->getOrder();
9
- $shipMethod = $order->getShippingMethod();
10
- if (strlen($shipMethod) > $len && substr($shipMethod, 0, $len) == "pbgsp_") {
11
- $totalTax = 0;
12
- $baseTotalTax = 0;
13
- $totalHiddenTax = 0;
14
- $baseTotalHiddenTax = 0;
15
- if ($order->getTaxAmount()) {
16
- $totalTax = $order->getTaxAmount();
17
- $baseTotalTax = $totalTax;
18
- }
19
- $invoice->setTaxAmount($totalTax);
20
- $invoice->setBaseTaxAmount($baseTotalTax);
21
- $invoice->setHiddenTaxAmount($totalHiddenTax);
22
- $invoice->setBaseHiddenTaxAmount($baseTotalHiddenTax);
23
-
24
- $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax + $totalHiddenTax);
25
- $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalHiddenTax);
26
- } else {
27
- parent::collect($invoice);
28
- }
29
-
30
- return $this;
31
- }
 
 
 
 
 
 
 
 
32
  }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Invoice/Duty.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ class Pb_Pbgsp_Model_Invoice_Duty extends Mage_Sales_Model_Order_Invoice_Total_Tax
11
+ {
12
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
13
+ {
14
+ Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Invoice_Duty.collect');
15
+ $len = strlen("pbgsp_");
16
+ $order = $invoice->getOrder();
17
+ $shipMethod = $order->getShippingMethod();
18
+ if (strlen($shipMethod) > $len && substr($shipMethod, 0, $len) == "pbgsp_") {
19
+ $totalTax = 0;
20
+ $baseTotalTax = 0;
21
+ $totalHiddenTax = 0;
22
+ $baseTotalHiddenTax = 0;
23
+ if ($order->getTaxAmount()) {
24
+ $totalTax = $order->getTaxAmount();
25
+ $baseTotalTax = $totalTax;
26
+ }
27
+ $invoice->setTaxAmount($totalTax);
28
+ $invoice->setBaseTaxAmount($baseTotalTax);
29
+ $invoice->setHiddenTaxAmount($totalHiddenTax);
30
+ $invoice->setBaseHiddenTaxAmount($baseTotalHiddenTax);
31
+
32
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax + $totalHiddenTax);
33
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalHiddenTax);
34
+ } else {
35
+ parent::collect($invoice);
36
+ }
37
+
38
+ return $this;
39
+ }
40
  }
app/code/local/Pb/Pbgsp/Model/Messages.php CHANGED
@@ -1,121 +1,127 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Messages {
4
- // protected $messages = array(
5
- // 101 => array(
6
- // "code" => "INTERNAL_ERROR",
7
- // "original" => "Internal Error.",
8
- // "display" => "Error 101: An error has occurred. Please contact the merchant for assistance."),
9
- // 102 => array(
10
- // "code" => "NULL_VALUE",
11
- // "original" => "Null value.",
12
- // "display" => "A required field is missing, please select a Province."),
13
- // 103 => array(
14
- // "code" => "INVALID_VALUE",
15
- // "original" => "Invalid value.",
16
- // "display" => "Error 103: An invalid value for a required non-null field has been submitted"),
17
- // 105 => array(
18
- // "code" => "MISSING_RECORD",
19
- // "original" => "Missing record.",
20
- // "display" => "Error 105: One or more items have not yet been prepared for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
21
- // 108 => array(
22
- // "code" => "CLASSIFICATION_NOT_AVAILABLE",
23
- // "original" => "Item cannot be classified.",
24
- // "display" => "Error 108: One or more items have not yet been prepared for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
25
- // 109 => array(
26
- // "code" => "QUANTITY_EXCEEDED",
27
- // "original" => "Quantity exceeded.",
28
- // "display" => "Error 109: The quantity of one or more selected items exceeds international shipping regulations. <IDENTIFY SKU>"),
29
- // 131 => array(
30
- // "code" => "SHIPPING_METHODS_NOT_AVAILABLE ",
31
- // "original" => "No shipping methods available. ",
32
- // "display" => "Error 131: No international shipping methods are available for the selected items."),
33
- // 139 => array(
34
- // "code" => "DUTY_NOT_AVAILABLE",
35
- // "original" => "Duties are not available.",
36
- // "display" => "Error 139: International duty items are not available for one or more items. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
37
- // 141 => array(
38
- // "code" => "MISSING_DUTIABLE_PRICE",
39
- // "original" => "Missing dutiable price.",
40
- // "display" => "Error 141: One or more selected items do not have a valid dutiable price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
41
- // 142 => array(
42
- // "code" => "INVALID_DUTIABLE_PRICE",
43
- // "original" => "Invalid dutiable price.",
44
- // "display" => "Error 142: One or more selected items do not have a valid dutiable price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
45
- // 144 => array(
46
- // "code" => "INVALID_SALE_PRICE",
47
- // "original" => "Invalid sale price.",
48
- // "display" => "Error 144: One or more items do not have a valid sale price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
49
- // 145 => array(
50
- // "code" => "TAX_NOT_AVAILABLE",
51
- // "original" => "Fail to retrieve taxes.",
52
- // "display" => "Error 145: One or more items does not have tax information for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
53
- // 154 => array(
54
- // "code" => "SHIPPING_CANNOT_BE_CALCULATED",
55
- // "original" => "Shipping cannot be calculated.",
56
- // "display" => "Error 154: The selected address is not valid for international delivery. Please note that FedEx cannot deliver to PO Boxes."),
57
- // 155 => array(
58
- // "code" => "SHIPPING_TARIFF_NOT_FOUND",
59
- // "original" => "Shipping tariff not found.",
60
- // "display" => "Error 155: The current basket of items exceeds international shipping guidelines. Please remove some items and try again."),
61
- // 161 => array(
62
- // "code" => "QUANTITY_SHIPPING_RESTRICTION",
63
- // "original" => "HS quantity shipping restriction.",
64
- // "display" => "Error 161: One or more items is restricted from international sale to the selected destination. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
65
- // 162 => array(
66
- // "code" => "QUANTITY_SHIPPING_RESTRICTION",
67
- // "original" => "HS quantity shipping restriction.",
68
- // "display" => "Error 161: One or more items exceed maximum value guidelines for international sale to the selected destination. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
69
- // 168 => array(
70
- // "code" => "SHIPPING_TARIFF_NOT_AVAILABLE",
71
- // "original" => "The weight of the item is exceeding the maximum accepted by tariffs.",
72
- // "display" => "Error 168: The weight of the basket exceeds international shipping guidelines. Please remove one or more items and try again."),
73
- // 174 => array(
74
- // "code" => "SHIPPING_SIZE_RESTRICTIONS",
75
- // "original" => "Item (commodity or merchant box) didn’t pass shipping size restrictions",
76
- // "display" => "Error 174: One or more selected items exceed dimensional limits for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
77
- // 175 => array(
78
- // "code" => "INVALID_PROVINCE_POSTALCODE_PAIR",
79
- // "original" => "Canada address validation failed (postal code does not match the province).",
80
- // "display" => "Error 175: The postal code and province entered do not match. Please check the postal code and province to ensure that they are entered correctly and try again."),
81
- // 176 => array(
82
- // "code" => "INVALID_POSTALCODE_FORMAT",
83
- // "original" => "Invalid Canadian Postal Code format (should be ldldld, where l=letter and d=digit).",
84
- // "display" => "Error 176: The postal code entered is invalid. Please check the postal code and try again."),
85
- // 177 => array(
86
- // "code" => "SHIPPING_VALUE_RESTRICTIONS",
87
- // "original" => "The order value exceeds Shipping Value Restrictions.",
88
- // "display" => "Error 177: The basket total exceeds maximum order value guidelines for international sale. Please remove items from the basket and try again."),
89
- // 1001 => array(
90
- // "code" => "LICENSE",
91
- // "original" => "Item is restricted for shipping due to license requirements.",
92
- // "display" => "Error 1001: One or more items is license restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
93
- // 1002 => array(
94
- // "code" => "SIZE",
95
- // "original" => "Item is restricted for shipping due to its size.",
96
- // "display" => "Error 1002: One or more items exceed size limits for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
97
- // 1003 => array(
98
- // "code" => "PROHIBITED",
99
- // "original" => "Item is restricted for shipping.",
100
- // "display" => "Error 1003: One or more items is restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
101
- // 1004 => array(
102
- // "code" => "CARRIER",
103
- // "original" => "Item is restricted for shipping due to a carrier restriction. The logistics carrier will not ship this product ",
104
- // "display" => "Error 1004: One or more items is restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
105
- // );
106
- //
107
- public function getDisplayMessage($code,$message) {
108
- // if (array_key_exists($code,$this->messages)) {
109
- // return $this->messages[$code]["display"];
110
- // }
111
-
112
- // moved to config
113
-
114
- $config_data = Mage::getStoreConfig('carriers/pbgsp/error_messages');
115
-
116
- if(isset($config_data["_$code"]['display']))
117
- return $config_data["_$code"]['display'];
118
-
119
- return $message;
120
- }
121
- }
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Messages.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Messages {
10
+ // protected $messages = array(
11
+ // 101 => array(
12
+ // "code" => "INTERNAL_ERROR",
13
+ // "original" => "Internal Error.",
14
+ // "display" => "Error 101: An error has occurred. Please contact the merchant for assistance."),
15
+ // 102 => array(
16
+ // "code" => "NULL_VALUE",
17
+ // "original" => "Null value.",
18
+ // "display" => "A required field is missing, please select a Province."),
19
+ // 103 => array(
20
+ // "code" => "INVALID_VALUE",
21
+ // "original" => "Invalid value.",
22
+ // "display" => "Error 103: An invalid value for a required non-null field has been submitted"),
23
+ // 105 => array(
24
+ // "code" => "MISSING_RECORD",
25
+ // "original" => "Missing record.",
26
+ // "display" => "Error 105: One or more items have not yet been prepared for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
27
+ // 108 => array(
28
+ // "code" => "CLASSIFICATION_NOT_AVAILABLE",
29
+ // "original" => "Item cannot be classified.",
30
+ // "display" => "Error 108: One or more items have not yet been prepared for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
31
+ // 109 => array(
32
+ // "code" => "QUANTITY_EXCEEDED",
33
+ // "original" => "Quantity exceeded.",
34
+ // "display" => "Error 109: The quantity of one or more selected items exceeds international shipping regulations. <IDENTIFY SKU>"),
35
+ // 131 => array(
36
+ // "code" => "SHIPPING_METHODS_NOT_AVAILABLE ",
37
+ // "original" => "No shipping methods available. ",
38
+ // "display" => "Error 131: No international shipping methods are available for the selected items."),
39
+ // 139 => array(
40
+ // "code" => "DUTY_NOT_AVAILABLE",
41
+ // "original" => "Duties are not available.",
42
+ // "display" => "Error 139: International duty items are not available for one or more items. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
43
+ // 141 => array(
44
+ // "code" => "MISSING_DUTIABLE_PRICE",
45
+ // "original" => "Missing dutiable price.",
46
+ // "display" => "Error 141: One or more selected items do not have a valid dutiable price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
47
+ // 142 => array(
48
+ // "code" => "INVALID_DUTIABLE_PRICE",
49
+ // "original" => "Invalid dutiable price.",
50
+ // "display" => "Error 142: One or more selected items do not have a valid dutiable price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
51
+ // 144 => array(
52
+ // "code" => "INVALID_SALE_PRICE",
53
+ // "original" => "Invalid sale price.",
54
+ // "display" => "Error 144: One or more items do not have a valid sale price for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
55
+ // 145 => array(
56
+ // "code" => "TAX_NOT_AVAILABLE",
57
+ // "original" => "Fail to retrieve taxes.",
58
+ // "display" => "Error 145: One or more items does not have tax information for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
59
+ // 154 => array(
60
+ // "code" => "SHIPPING_CANNOT_BE_CALCULATED",
61
+ // "original" => "Shipping cannot be calculated.",
62
+ // "display" => "Error 154: The selected address is not valid for international delivery. Please note that FedEx cannot deliver to PO Boxes."),
63
+ // 155 => array(
64
+ // "code" => "SHIPPING_TARIFF_NOT_FOUND",
65
+ // "original" => "Shipping tariff not found.",
66
+ // "display" => "Error 155: The current basket of items exceeds international shipping guidelines. Please remove some items and try again."),
67
+ // 161 => array(
68
+ // "code" => "QUANTITY_SHIPPING_RESTRICTION",
69
+ // "original" => "HS quantity shipping restriction.",
70
+ // "display" => "Error 161: One or more items is restricted from international sale to the selected destination. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
71
+ // 162 => array(
72
+ // "code" => "QUANTITY_SHIPPING_RESTRICTION",
73
+ // "original" => "HS quantity shipping restriction.",
74
+ // "display" => "Error 161: One or more items exceed maximum value guidelines for international sale to the selected destination. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
75
+ // 168 => array(
76
+ // "code" => "SHIPPING_TARIFF_NOT_AVAILABLE",
77
+ // "original" => "The weight of the item is exceeding the maximum accepted by tariffs.",
78
+ // "display" => "Error 168: The weight of the basket exceeds international shipping guidelines. Please remove one or more items and try again."),
79
+ // 174 => array(
80
+ // "code" => "SHIPPING_SIZE_RESTRICTIONS",
81
+ // "original" => "Item (commodity or merchant box) didn’t pass shipping size restrictions",
82
+ // "display" => "Error 174: One or more selected items exceed dimensional limits for international sale. Please remove the item(s) from your basket and try again. <IDENTIFY SKU>"),
83
+ // 175 => array(
84
+ // "code" => "INVALID_PROVINCE_POSTALCODE_PAIR",
85
+ // "original" => "Canada address validation failed (postal code does not match the province).",
86
+ // "display" => "Error 175: The postal code and province entered do not match. Please check the postal code and province to ensure that they are entered correctly and try again."),
87
+ // 176 => array(
88
+ // "code" => "INVALID_POSTALCODE_FORMAT",
89
+ // "original" => "Invalid Canadian Postal Code format (should be ldldld, where l=letter and d=digit).",
90
+ // "display" => "Error 176: The postal code entered is invalid. Please check the postal code and try again."),
91
+ // 177 => array(
92
+ // "code" => "SHIPPING_VALUE_RESTRICTIONS",
93
+ // "original" => "The order value exceeds Shipping Value Restrictions.",
94
+ // "display" => "Error 177: The basket total exceeds maximum order value guidelines for international sale. Please remove items from the basket and try again."),
95
+ // 1001 => array(
96
+ // "code" => "LICENSE",
97
+ // "original" => "Item is restricted for shipping due to license requirements.",
98
+ // "display" => "Error 1001: One or more items is license restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
99
+ // 1002 => array(
100
+ // "code" => "SIZE",
101
+ // "original" => "Item is restricted for shipping due to its size.",
102
+ // "display" => "Error 1002: One or more items exceed size limits for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
103
+ // 1003 => array(
104
+ // "code" => "PROHIBITED",
105
+ // "original" => "Item is restricted for shipping.",
106
+ // "display" => "Error 1003: One or more items is restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
107
+ // 1004 => array(
108
+ // "code" => "CARRIER",
109
+ // "original" => "Item is restricted for shipping due to a carrier restriction. The logistics carrier will not ship this product ",
110
+ // "display" => "Error 1004: One or more items is restricted for international sale. Please remove the item(s) and try again. <IDENTIFY SKU>"),
111
+ // );
112
+ //
113
+ public function getDisplayMessage($code,$message) {
114
+ // if (array_key_exists($code,$this->messages)) {
115
+ // return $this->messages[$code]["display"];
116
+ // }
117
+
118
+ // moved to config
119
+
120
+ $config_data = Mage::getStoreConfig('carriers/pbgsp/error_messages');
121
+
122
+ if(isset($config_data["_$code"]['display']))
123
+ return $config_data["_$code"]['display'];
124
+
125
+ return $message;
126
+ }
127
+ }
app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel.php CHANGED
@@ -1,9 +1,16 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Inboundparcel extends Mage_Core_Model_Mysql4_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/inboundparcel', 'inbound_parcel_id');
6
- }
7
- }
8
-
9
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Mysql4_Inboundparcel extends Mage_Core_Model_Mysql4_Abstract {
10
+ public function _construct()
11
+ {
12
+ $this->_init('pb_pbgsp/inboundparcel', 'inbound_parcel_id');
13
+ }
14
+ }
15
+
16
+ ?>
app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel/Collection.php CHANGED
@@ -1,8 +1,16 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Inboundparcel_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/inboundparcel');
6
- }
7
- }
8
- ?>
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Inboundparcel/Collection.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ class Pb_Pbgsp_Model_Mysql4_Inboundparcel_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+ public function _construct()
12
+ {
13
+ $this->_init('pb_pbgsp/inboundparcel');
14
+ }
15
+ }
16
+ ?>
app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber.php CHANGED
@@ -1,9 +1,16 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Ordernumber extends Mage_Core_Model_Mysql4_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/ordernumber', 'ordernumber_id');
6
- }
7
- }
8
-
9
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Mysql4_Ordernumber extends Mage_Core_Model_Mysql4_Abstract {
10
+ public function _construct()
11
+ {
12
+ $this->_init('pb_pbgsp/ordernumber', 'ordernumber_id');
13
+ }
14
+ }
15
+
16
+ ?>
app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber/Collection.php CHANGED
@@ -1,8 +1,15 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Ordernumber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/ordernumber');
6
- }
7
- }
8
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Ordernumber/Collection.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Mysql4_Ordernumber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
10
+ public function _construct()
11
+ {
12
+ $this->_init('pb_pbgsp/ordernumber');
13
+ }
14
+ }
15
+ ?>
app/code/local/Pb/Pbgsp/Model/Mysql4/Variable.php CHANGED
@@ -1,9 +1,16 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Variable extends Mage_Core_Model_Mysql4_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/variable', 'variable_id');
6
- }
7
- }
8
-
9
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Variable.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Mysql4_Variable extends Mage_Core_Model_Mysql4_Abstract {
10
+ public function _construct()
11
+ {
12
+ $this->_init('pb_pbgsp/variable', 'variable_id');
13
+ }
14
+ }
15
+
16
+ ?>
app/code/local/Pb/Pbgsp/Model/Mysql4/Variable/Collection.php CHANGED
@@ -1,8 +1,15 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Mysql4_Variable_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
3
- public function _construct()
4
- {
5
- $this->_init('pb_pbgsp/variable');
6
- }
7
- }
8
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Mysql4/Variable/Collection.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Mysql4_Variable_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
10
+ public function _construct()
11
+ {
12
+ $this->_init('pb_pbgsp/variable');
13
+ }
14
+ }
15
+ ?>
app/code/local/Pb/Pbgsp/Model/Observer.php CHANGED
@@ -1,318 +1,340 @@
1
- <?php
2
- class Pb_Pbgsp_Model_Observer {
3
- const MODULE_NAME = 'Pb_Pbgsp';
4
- public function __construct() {
5
- }
6
-
7
- public function isPbOrder($address) {
8
- $shipMethod = $address->getShippingMethod();
9
- $len = strlen("pbgsp_");
10
- if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
11
- return true;
12
- }
13
- Pb_Pbgsp_Model_Util::log("Shipping method". $shipMethod);
14
- return false;
15
-
16
- }
17
-
18
-
19
- public function getShipMethod($observer) {
20
- Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.getShipMethod');
21
- $shipMethod = $observer->getQuote()->getShippingAddress()->getShippingMethod();
22
-
23
- return substr($shipMethod,strlen("pbgsp_"));
24
- }
25
-
26
- public function generateInboundParcelPreAdvice($observer) {
27
-
28
- if(Pb_Pbgsp_Model_Credentials::isASNGenerationEnabled() == '1') {
29
- try {
30
- $shipment = $observer->getEvent()->getShipment();
31
- $order = $shipment->getOrder();
32
- /* @var $order Mage_Sales_Model_Order */
33
-
34
- if(!$this->isPbOrder($order))
35
- return;
36
- //check if ASN already generated or not
37
- $parcel = Mage::getModel("pb_pbgsp/inboundparcel")-> getCollection();
38
- $parcel -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
39
- if(count($parcel) > 0)
40
- return;
41
- Pb_Pbgsp_Model_Util::log("Generting ASN.");
42
- $clearPathOrders = Mage::getModel("pb_pbgsp/ordernumber")-> getCollection();
43
- $clearPathOrders -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
44
- foreach ($clearPathOrders as $cpOrder) {
45
- $cpOrderNumber = $cpOrder -> getCpOrderNumber();
46
- $tracks = array();
47
- $items = array();
48
- foreach($shipment->getTracksCollection() as $track) {
49
- $tracks[] = $track;
50
- }
51
- foreach($shipment->getItemsCollection() as $item) {
52
-
53
- $items[] = $item;
54
-
55
- }
56
-
57
- $parcelResponse = Pb_Pbgsp_Model_Api::generateInboundParcelNumber($shipment,$items,$order -> getRealOrderId(),$cpOrderNumber);
58
- if(array_key_exists('errors',$parcelResponse)) {
59
- Pb_Pbgsp_Model_Util::log("Error generating inbound parcel");
60
- Pb_Pbgsp_Model_Util::log($parcelResponse);
61
- }
62
- else {
63
- $cpParcel = Mage::getModel('pb_pbgsp/inboundparcel');
64
- $cpParcel->setInboundParcel($parcelResponse['parcelIdentifier']);
65
- $cpParcel->setMageOrderNumber( $order->getRealOrderId());
66
- $cpParcel->setPbOrderNumber( $cpOrderNumber);
67
- $cpParcel->save();
68
- Pb_Pbgsp_Model_Util::log('Inbound Parcel Number Saved');
69
- }
70
-
71
- }
72
-
73
-
74
- }
75
- catch(Exception $e) {
76
- Pb_Pbgsp_Model_Util::log("Error creating inbound parcel. ");
77
- Pb_Pbgsp_Model_Util::logException($e);
78
- }
79
- }
80
-
81
- }
82
- public function createPbOrder($observer) {
83
- // Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.createPbOrder');
84
- Mage::getSingleton("customer/session")->setPbDutyAndTax(0);
85
- $mageOrderNumber = Mage::getSingleton('checkout/session')->getLastRealOrderId();
86
- $order = Mage::getModel('sales/order')->loadByIncrementId($mageOrderNumber);
87
- Pb_Pbgsp_Model_Util::log(" createPbOrder");
88
- if ($this->isPbOrder($order)) {
89
- $orderNumber = Mage::getSingleton("customer/session")->getPbOrderNumber();
90
-
91
- // Save in DB
92
-
93
- $orderNumber->setMageOrderNumber($mageOrderNumber);
94
- //$orderNumber->setCpOrderNumber($cpOrderNumber);
95
- Pb_Pbgsp_Model_Util::log($orderNumber->getHubId());
96
- Pb_Pbgsp_Model_Util::log($orderNumber->getHubCountry());
97
- $orderNumber->setConfirmed(false);
98
- $orderNumber->setReferenced(false);
99
- $orderNumber->save();
100
- Pb_Pbgsp_Model_Util::log("calling PB confirm order for $mageOrderNumber");
101
- if (Pb_Pbgsp_Model_Api::confirmOrder($orderNumber->getCpOrderNumber(),$order)) {
102
- $orderNumber->setConfirmed(true);
103
- $orderNumber->setReferenced(true);
104
- $orderNumber->save();
105
- Pb_Pbgsp_Model_Util::log(" $mageOrderNumber order is confirmed in PB");
106
- }
107
- // if (Pb_Pbgsp_Model_Api::setOrderReference($cpOrderNumber,$mageOrderNumber)) {
108
- // $orderNumber->setReferenced(true);
109
- // $orderNumber->save();
110
- // }
111
- }
112
- else {
113
- Pb_Pbgsp_Model_Util::log("$mageOrderNumber not PB order");
114
- }
115
-
116
- }
117
-
118
- public function saveShippingMethod($observer) {
119
- // Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.saveShippingMethod');
120
- //TODO: If anything fails here I need to fail the checkout process.
121
- $address = $observer->getQuote()->getShippingAddress();
122
- if ($this->isPbOrder($address)) {
123
- Pb_Pbgsp_Model_Util::log(" PB order");
124
- $items = Mage::getSingleton('checkout/cart')->getItems();
125
- $shipMethod = $this->getShipMethod($observer);
126
- $order = Pb_Pbgsp_Model_Api::createOrder($items,$shipMethod,$address);
127
- if (!$order) {
128
- Mage::throwException("Unable to create Pb order.");
129
- }
130
-
131
- Mage::getSingleton("customer/session")->setPbDutyAndTax($order['order']['totalImportation']['total']['value']);
132
-
133
- $orderNumber = Mage::getModel("pb_pbgsp/ordernumber");
134
-
135
- $orderNumber->setCpOrderNumber($order["orderId"]);
136
- $orderNumber->setHubId($order["shipToHub"]['hubId']);
137
- $orderNumber->setHubStreet1($order["shipToHub"]['hubAddress']['street1']);
138
- $orderNumber->setHubStreet2($order["shipToHub"]['hubAddress']['street2']);
139
- $orderNumber->setHubProvinceOrState($order["shipToHub"]['hubAddress']['provinceOrState']);
140
- $orderNumber->setHubCountry($order["shipToHub"]['hubAddress']['country']);
141
-
142
- Mage::getSingleton("customer/session")->setPbOrderNumber($orderNumber);
143
- } else {
144
- Pb_Pbgsp_Model_Util::log(" not clearpath order");
145
- Mage::getSingleton("customer/session")->setPbDutyAndTax(false);
146
- Mage::getSingleton("customer/session")->setPbOrderNumber(false);
147
- }
148
- }
149
-
150
- public function addDutiesOnEstimation($observer){
151
- //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.addDutiesOnEstimation');
152
- Mage::getSingleton("customer/session")->setPbDutyAndTax(false);//Added by BigPixel to clear previous values, 10/20/2013
153
- $clearPathMethods = Mage::getSingleton('checkout/session')->getPbMethods();
154
- $quote = Mage::getSingleton('checkout/session')->getQuote();
155
- $selectedMethod = null;
156
- if($quote->getShippingAddress()){
157
- $selectedMethod = $quote->getShippingAddress()->getShippingMethod();
158
- }
159
-
160
- if($selectedMethod){
161
- $selectedMethod = preg_replace('/pbgsp_/', '',$selectedMethod);
162
- foreach($clearPathMethods as $clearPathMethod){
163
- Pb_Pbgsp_Model_Util::log('addDutiesOnEstimation method'.$clearPathMethod->getMethod().' and tax'.$clearPathMethod->getTax());
164
- if($clearPathMethod->getMethod() == $selectedMethod){
165
- Mage::getSingleton("customer/session")->setPbDutyAndTax($clearPathMethod->getTax());
166
- }
167
- }
168
- }
169
- }
170
-
171
- public function modifyOrderView($observer = NULL) {
172
-
173
- //return;
174
- if (!$observer) {
175
- return;
176
- }
177
- if (Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME))
178
- return;
179
- $transport = $observer->getEvent()->getTransport();
180
- $layoutName = $observer->getEvent()->getBlock()->getNameInLayout();
181
- if ('order_info' == $layoutName) {
182
-
183
- if (!Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME)) {
184
-
185
-
186
- $cpOrderNumber = $this->_getCpOrderNumber($observer->getEvent()->getBlock()->getOrder());
187
- if($cpOrderNumber) {
188
- $html = "<div class='entry-edit'>
189
- <div class='entry-edit-head'>
190
- <h4 class='icon-head '>Pitney Bowes Shipments</h4>
191
- </div>
192
- <fieldset>
193
- <strong>PB Order Number</strong>
194
- <span>".$cpOrderNumber->getCpOrderNumber()."</span><br/>
195
- <strong>Hub ID</strong>
196
- <span>".$cpOrderNumber->getHubId()."</span><br/>
197
- <strong>Hub Street 1</strong>
198
- <span>".$cpOrderNumber->getHubStreet1()."</span><br/>
199
- <strong>Hub Street 2</strong>
200
- <span>".$cpOrderNumber->getHubStreet2()."</span><br/>
201
- <strong>Hub Province/State</strong>
202
- <span>".$cpOrderNumber->getHubProvinceOrState()."</span><br/>
203
- <strong>Hub Zip</strong>
204
- <span>".$cpOrderNumber->getHubPostCode()."</span><br/>
205
- <strong>Hub Country</strong>
206
- <span>".$cpOrderNumber->getHubCountry()."</span><br/>
207
- </fieldset>
208
- </div>";
209
- $transport['html'] = $transport['html'] . $html;
210
- }
211
-
212
-
213
- }
214
- }
215
- else if('email/order/shipment/track.phtml' == $observer->getEvent()->getBlock()->getTemplate()) {
216
- if(!Mage::getStoreConfig('carriers/pbgsp/trackinglink'))
217
- return;
218
-
219
- $cpord = $this->_getCPORD($observer->getEvent()->getBlock()->getOrder());
220
- if($cpord) {
221
- $staging = 0;
222
- if(strpos(Pb_Pbgsp_Model_Credentials::getApiUrl(),'cpsandbox') >=0)
223
- $staging = 1;
224
- $transport['html'] = "<a href='http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging'>Track your order</a>";
225
- }
226
-
227
- }
228
- else if('shipping.tracking.popup' == $layoutName) {
229
- if(!Mage::getStoreConfig('carriers/pbgsp/trackinglink'))
230
- return;
231
-
232
- $helper = Mage::helper('shipping');
233
- $data = $helper->decodeTrackingHash($observer->getEvent()->getBlock()->getRequest()->getParam('hash'));
234
-
235
- $orderId = null;
236
- if($data['key'] == 'order_id')
237
- $orderId = $data['id'];
238
- else if($data['key'] == 'ship_id') {
239
- /* @var $model Mage_Sales_Model_Order_Shipment */
240
- $model = Mage::getModel('sales/order_shipment');
241
- $ship = $model->load($data['id']);
242
- $orderId = $model->getOrderId();
243
- }
244
- else if($data['key'] == 'track_id') {
245
- $track = Mage::getModel('sales/order_shipment_track')->load($data['id']);
246
- $orderId = $track->getOrderId();
247
- }
248
- if(!$orderId)
249
- return;
250
- $cpord = $this->_getCPORD(Mage::getModel('sales/order')->load($orderId));
251
- if($cpord) {
252
- $staging = 0;
253
- if(strpos(Pb_Pbgsp_Model_Credentials::getApiUrl(),'cpsandbox') >=0)
254
- $staging = 1;
255
- $script = "<script lang='javascript'>
256
- window.location = 'http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging';
257
- </script>
258
- ";
259
- $transport['html'] = $script;
260
- }
261
-
262
- }
263
- else
264
- // if( 'checkout.onepage.review' == $layoutName
265
- // || 'checkout.onepage.review.info.totals' == $layoutName
266
- // || 'checkout.cart.totals' == $layoutName)
267
- {
268
- //replace "Shipping & Handling" to "Transportation Charges" and "Duty & Taxes" to "Importation Charges"
269
- $html = $transport['html'];
270
- $pbTitle = Mage::getStoreConfig('carriers/pbgsp/title');
271
- if(strpos($html,$pbTitle) !== false) {
272
- $html = str_replace("Shipping &amp; Handling","Transportation Charges",$html);
273
- $html = str_replace("Shipping & Handling","Transportation Charges",$html);
274
- $html = str_replace("Duty & Taxes","Importation Charges",$html);
275
- $html = str_replace("Duty &amp; Taxes","Importation Charges",$html);
276
- $transport['html'] = $html;
277
- }
278
-
279
- }
280
- // else {
281
- //
282
- // }
283
- // else {
284
- // $html = $transport['html'];
285
- // if(strpos('Shipping & Handling',$html) >= 0)
286
- // Pb_Pbgsp_Model_Util::log("Found in $layoutName");
287
- // }
288
-
289
- return $this;
290
- }
291
- private function _getCPORD($order)
292
- {
293
- if($order) {
294
- $cpOrder = $this->_getCpOrderNumber($order);
295
- if($cpOrder) {
296
- return $cpOrder -> getCpOrderNumber();
297
- }
298
-
299
- }
300
-
301
- return false;
302
- }
303
- private function _getCpOrderNumber($order)
304
- {
305
- if($order) {
306
- $clearPathOrders = Mage::getModel("pb_pbgsp/ordernumber")-> getCollection();
307
-
308
- $clearPathOrders -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
309
- foreach ($clearPathOrders as $cpOrder) {
310
- return $cpOrder ;
311
-
312
- }
313
- }
314
-
315
- return false;
316
- }
317
- }
318
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Observer.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Observer {
10
+ const MODULE_NAME = 'Pb_Pbgsp';
11
+ public function __construct() {
12
+ }
13
+
14
+ public function isPbOrder($address) {
15
+ $shipMethod = $address->getShippingMethod();
16
+ $len = strlen("pbgsp_");
17
+ if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
18
+ return true;
19
+ }
20
+ Pb_Pbgsp_Model_Util::log("Shipping method". $shipMethod);
21
+ return false;
22
+
23
+ }
24
+
25
+ public function productLoadAfter($observer) {
26
+ $event = $observer->getEvent();
27
+ $product = $event->getProduct();
28
+ $product->lockAttribute('pb_pbgsp_upload');
29
+ }
30
+ public function categoryLoadAfter($observer) {
31
+ $event = $observer->getEvent();
32
+ $category = $event->getCategory();
33
+ $category->lockAttribute('pb_pbgsp_upload');
34
+ }
35
+ public function getShipMethod($observer) {
36
+ Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.getShipMethod');
37
+ $shipMethod = $observer->getQuote()->getShippingAddress()->getShippingMethod();
38
+
39
+ return substr($shipMethod,strlen("pbgsp_"));
40
+ }
41
+
42
+ public function generateInboundParcelPreAdvice($observer) {
43
+
44
+ if(Pb_Pbgsp_Model_Credentials::isASNGenerationEnabled() == '1') {
45
+ try {
46
+ $shipment = $observer->getEvent()->getShipment();
47
+ $order = $shipment->getOrder();
48
+ /* @var $order Mage_Sales_Model_Order */
49
+
50
+ if(!$this->isPbOrder($order))
51
+ return;
52
+ //check if ASN already generated or not
53
+ $parcel = Mage::getModel("pb_pbgsp/inboundparcel")-> getCollection();
54
+ $parcel -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
55
+ if(count($parcel) > 0)
56
+ return;
57
+ Pb_Pbgsp_Model_Util::log("Generting ASN.");
58
+ $clearPathOrders = Mage::getModel("pb_pbgsp/ordernumber")-> getCollection();
59
+ $clearPathOrders -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
60
+ foreach ($clearPathOrders as $cpOrder) {
61
+ $cpOrderNumber = $cpOrder -> getCpOrderNumber();
62
+ $tracks = array();
63
+ $items = array();
64
+ foreach($shipment->getTracksCollection() as $track) {
65
+ $tracks[] = $track;
66
+ }
67
+ foreach($shipment->getItemsCollection() as $item) {
68
+
69
+ $items[] = $item;
70
+
71
+ }
72
+
73
+ $parcelResponse = Pb_Pbgsp_Model_Api::generateInboundParcelNumber($shipment,$items,$order -> getRealOrderId(),$cpOrderNumber);
74
+ if(array_key_exists('errors',$parcelResponse)) {
75
+ Pb_Pbgsp_Model_Util::log("Error generating inbound parcel");
76
+ Pb_Pbgsp_Model_Util::log($parcelResponse);
77
+ }
78
+ else {
79
+ $cpParcel = Mage::getModel('pb_pbgsp/inboundparcel');
80
+ $cpParcel->setInboundParcel($parcelResponse['parcelIdentifier']);
81
+ $cpParcel->setMageOrderNumber( $order->getRealOrderId());
82
+ $cpParcel->setPbOrderNumber( $cpOrderNumber);
83
+ $cpParcel->save();
84
+ Pb_Pbgsp_Model_Util::log('Inbound Parcel Number Saved');
85
+ }
86
+
87
+ }
88
+
89
+
90
+ }
91
+ catch(Exception $e) {
92
+ Pb_Pbgsp_Model_Util::log("Error creating inbound parcel. ");
93
+ Pb_Pbgsp_Model_Util::logException($e);
94
+ }
95
+ }
96
+
97
+ }
98
+ public function createPbOrder($observer) {
99
+ // Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.createPbOrder');
100
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(0);
101
+ $mageOrderNumber = Mage::getSingleton('checkout/session')->getLastRealOrderId();
102
+ $order = Mage::getModel('sales/order')->loadByIncrementId($mageOrderNumber);
103
+ Pb_Pbgsp_Model_Util::log(" createPbOrder");
104
+ if ($this->isPbOrder($order)) {
105
+ $orderNumber = Mage::getSingleton("customer/session")->getPbOrderNumber();
106
+
107
+ // Save in DB
108
+
109
+ $orderNumber->setMageOrderNumber($mageOrderNumber);
110
+ //$orderNumber->setCpOrderNumber($cpOrderNumber);
111
+ Pb_Pbgsp_Model_Util::log($orderNumber->getHubId());
112
+ Pb_Pbgsp_Model_Util::log($orderNumber->getHubCountry());
113
+ $orderNumber->setConfirmed(false);
114
+ $orderNumber->setReferenced(false);
115
+ $orderNumber->save();
116
+ Pb_Pbgsp_Model_Util::log("calling PB confirm order for $mageOrderNumber");
117
+ if (Pb_Pbgsp_Model_Api::confirmOrder($orderNumber->getCpOrderNumber(),$order)) {
118
+ $orderNumber->setConfirmed(true);
119
+ $orderNumber->setReferenced(true);
120
+ $orderNumber->save();
121
+ Pb_Pbgsp_Model_Util::log(" $mageOrderNumber order is confirmed in PB");
122
+ }
123
+ // if (Pb_Pbgsp_Model_Api::setOrderReference($cpOrderNumber,$mageOrderNumber)) {
124
+ // $orderNumber->setReferenced(true);
125
+ // $orderNumber->save();
126
+ // }
127
+ }
128
+ else {
129
+ Pb_Pbgsp_Model_Util::log("$mageOrderNumber not PB order");
130
+ }
131
+
132
+ }
133
+
134
+ public function saveShippingMethod($observer) {
135
+ // Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.saveShippingMethod');
136
+ //TODO: If anything fails here I need to fail the checkout process.
137
+ $address = $observer->getQuote()->getShippingAddress();
138
+ if ($this->isPbOrder($address)) {
139
+ Pb_Pbgsp_Model_Util::log(" PB order");
140
+ $items = Mage::getSingleton('checkout/cart')->getItems();
141
+ $shipMethod = $this->getShipMethod($observer);
142
+ $order = Pb_Pbgsp_Model_Api::createOrder($items,$shipMethod,$address);
143
+ if (!$order) {
144
+ Mage::throwException("Unable to create Pb order.");
145
+ }
146
+
147
+ $tax = $order['order']['totalImportation']['total']['value'];
148
+ if(Pb_Pbgsp_Model_Credentials::isFreeTaxEnabled())
149
+ $tax = 0;
150
+ Mage::getSingleton("customer/session")->setPbDutyAndTax($tax);
151
+
152
+ $orderNumber = Mage::getModel("pb_pbgsp/ordernumber");
153
+
154
+ $orderNumber->setCpOrderNumber($order["orderId"]);
155
+ $orderNumber->setHubId($order["shipToHub"]['hubId']);
156
+ $orderNumber->setHubStreet1($order["shipToHub"]['hubAddress']['street1']);
157
+ $orderNumber->setHubStreet2($order["shipToHub"]['hubAddress']['street2']);
158
+ $orderNumber->setHubProvinceOrState($order["shipToHub"]['hubAddress']['provinceOrState']);
159
+ $orderNumber->setHubCountry($order["shipToHub"]['hubAddress']['country']);
160
+ $orderNumber->setHubPostalCode($order["shipToHub"]['hubAddress']['postalOrZipCode']);
161
+
162
+ Mage::getSingleton("customer/session")->setPbOrderNumber($orderNumber);
163
+ } else {
164
+ Pb_Pbgsp_Model_Util::log(" not clearpath order");
165
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(false);
166
+ Mage::getSingleton("customer/session")->setPbOrderNumber(false);
167
+ }
168
+ }
169
+
170
+ public function addDutiesOnEstimation($observer){
171
+ //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Observer.addDutiesOnEstimation');
172
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(false);//Added by BigPixel to clear previous values, 10/20/2013
173
+ $clearPathMethods = Mage::getSingleton('checkout/session')->getPbMethods();
174
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
175
+ $selectedMethod = null;
176
+ if($quote->getShippingAddress()){
177
+ $selectedMethod = $quote->getShippingAddress()->getShippingMethod();
178
+ }
179
+
180
+ if($selectedMethod){
181
+ $selectedMethod = preg_replace('/pbgsp_/', '',$selectedMethod);
182
+ foreach($clearPathMethods as $clearPathMethod){
183
+ Pb_Pbgsp_Model_Util::log('addDutiesOnEstimation method'.$clearPathMethod->getMethod().' and tax'.$clearPathMethod->getTax());
184
+ if($clearPathMethod->getMethod() == $selectedMethod){
185
+ Mage::getSingleton("customer/session")->setPbDutyAndTax($clearPathMethod->getTax());
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ public function modifyOrderView($observer = NULL) {
192
+
193
+ //return;
194
+ if (!$observer) {
195
+ return;
196
+ }
197
+ if (Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME))
198
+ return;
199
+ $transport = $observer->getEvent()->getTransport();
200
+ $layoutName = $observer->getEvent()->getBlock()->getNameInLayout();
201
+ if ('order_info' == $layoutName) {
202
+
203
+ if (!Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME)) {
204
+
205
+
206
+ $cpOrderNumber = $this->_getCpOrderNumber($observer->getEvent()->getBlock()->getOrder());
207
+ if($cpOrderNumber) {
208
+ $html = "<div class='entry-edit'>
209
+ <div class='entry-edit-head'>
210
+ <h4 class='icon-head '>Pitney Bowes Shipments</h4>
211
+ </div>
212
+ <fieldset>
213
+ <strong>PB Order Number</strong>
214
+ <span>".$cpOrderNumber->getCpOrderNumber()."</span><br/>
215
+ <strong>Hub ID</strong>
216
+ <span>".$cpOrderNumber->getHubId()."</span><br/>
217
+ <strong>Hub Street 1</strong>
218
+ <span>".$cpOrderNumber->getHubStreet1()."</span><br/>
219
+ <strong>Hub Street 2</strong>
220
+ <span>".$cpOrderNumber->getHubStreet2()."</span><br/>
221
+ <strong>Postal Code</strong>
222
+ <span>".$cpOrderNumber->getHubPostalCode()."</span><br/>
223
+ <strong>Hub Province/State</strong>
224
+ <span>".$cpOrderNumber->getHubProvinceOrState()."</span><br/>
225
+ <strong>Hub Country</strong>
226
+ <span>".$cpOrderNumber->getHubCountry()."</span><br/>
227
+ </fieldset>
228
+ </div>";
229
+ $transport['html'] = $transport['html'] . $html;
230
+ }
231
+
232
+
233
+ }
234
+ }
235
+ else if('email/order/shipment/track.phtml' == $observer->getEvent()->getBlock()->getTemplate()) {
236
+ if(!Mage::getStoreConfig('carriers/pbgsp/trackinglink'))
237
+ return;
238
+
239
+ $cpord = $this->_getCPORD($observer->getEvent()->getBlock()->getOrder());
240
+ if($cpord) {
241
+ $staging = 0;
242
+ if(strpos(Pb_Pbgsp_Model_Credentials::getCheckoutUrl(),'cpsandbox') >=0)
243
+ $staging = 1;
244
+ $transport['html'] = "<a href='http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging'>Track your order</a>";
245
+ }
246
+
247
+ }
248
+ else if('shipping.tracking.popup' == $layoutName) {
249
+ if(!Mage::getStoreConfig('carriers/pbgsp/trackinglink'))
250
+ return;
251
+
252
+ $helper = Mage::helper('shipping');
253
+ $data = $helper->decodeTrackingHash($observer->getEvent()->getBlock()->getRequest()->getParam('hash'));
254
+
255
+ $orderId = null;
256
+ if($data['key'] == 'order_id')
257
+ $orderId = $data['id'];
258
+ else if($data['key'] == 'ship_id') {
259
+ /* @var $model Mage_Sales_Model_Order_Shipment */
260
+ $model = Mage::getModel('sales/order_shipment');
261
+ $ship = $model->load($data['id']);
262
+ $orderId = $model->getOrderId();
263
+ }
264
+ else if($data['key'] == 'track_id') {
265
+ $track = Mage::getModel('sales/order_shipment_track')->load($data['id']);
266
+ $orderId = $track->getOrderId();
267
+ }
268
+ if(!$orderId)
269
+ return;
270
+ $cpord = $this->_getCPORD(Mage::getModel('sales/order')->load($orderId));
271
+ if($cpord) {
272
+ $staging = 0;
273
+ if(strpos(Pb_Pbgsp_Model_Credentials::getCheckoutUrl(),'cpsandbox') >=0)
274
+ $staging = 1;
275
+ $script = "<script lang='javascript'>
276
+ window.location = 'http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging';
277
+ </script>
278
+ ";
279
+ $transport['html'] = $script;
280
+ }
281
+
282
+ }
283
+ else
284
+ // if( 'checkout.onepage.review' == $layoutName
285
+ // || 'checkout.onepage.review.info.totals' == $layoutName
286
+ // || 'checkout.cart.totals' == $layoutName)
287
+ {
288
+ //replace "Shipping & Handling" to "Transportation Charges" and "Duty & Taxes" to "Importation Charges"
289
+ $html = $transport['html'];
290
+ $pbTitle = Mage::getStoreConfig('carriers/pbgsp/title');
291
+ if(strpos($html,$pbTitle) !== false) {
292
+ $html = str_replace("Shipping &amp; Handling","Transportation Charges",$html);
293
+ $html = str_replace("Shipping & Handling","Transportation Charges",$html);
294
+ $html = str_replace("Duty & Taxes","Importation Charges",$html);
295
+ $html = str_replace("Duty &amp; Taxes","Importation Charges",$html);
296
+ $transport['html'] = $html;
297
+ }
298
+
299
+ }
300
+ // else {
301
+ //
302
+ // }
303
+ // else {
304
+ // $html = $transport['html'];
305
+ // if(strpos('Shipping & Handling',$html) >= 0)
306
+ // Pb_Pbgsp_Model_Util::log("Found in $layoutName");
307
+ // }
308
+
309
+ return $this;
310
+ }
311
+ private function _getCPORD($order)
312
+ {
313
+ if($order) {
314
+ $cpOrder = $this->_getCpOrderNumber($order);
315
+ if($cpOrder) {
316
+ return $cpOrder -> getCpOrderNumber();
317
+ }
318
+
319
+ }
320
+
321
+ return false;
322
+ }
323
+ private function _getCpOrderNumber($order)
324
+ {
325
+ if($order) {
326
+ // $clearPathOrders = Mage::getModel("pb_pbgsp/ordernumber")-> getCollection();
327
+ //
328
+ // $clearPathOrders -> addFieldToFilter('mage_order_number', $order -> getRealOrderId());
329
+ // foreach ($clearPathOrders as $cpOrder) {
330
+ // return $cpOrder ;
331
+ //
332
+ // }
333
+ $cpOrder = Mage::getModel("pb_pbgsp/ordernumber")->load($order -> getRealOrderId(),'mage_order_number');
334
+ return $cpOrder;
335
+ }
336
+
337
+ return false;
338
+ }
339
+ }
340
+ ?>
app/code/local/Pb/Pbgsp/Model/Ordernumber.php CHANGED
@@ -1,11 +1,17 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Ordernumber extends Mage_Core_Model_Abstract {
4
- public function _construct()
5
- {
6
- parent::_construct();
7
- $this->_init('pb_pbgsp/ordernumber');
8
- }
9
- }
10
-
11
- ?>
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Ordernumber.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Ordernumber extends Mage_Core_Model_Abstract {
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('pb_pbgsp/ordernumber');
14
+ }
15
+ }
16
+
17
+ ?>
app/code/local/Pb/Pbgsp/Model/Pdf/Tax.php CHANGED
@@ -1,14 +1,21 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Pdf_Tax extends Mage_Tax_Model_Sales_Pdf_Tax {
4
- public function getTitle() {
5
- $shipMethod = $this->getOrder()->getShippingMethod();
6
- $len = strlen("pbgsp_");
7
- if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
8
- return "Importation Charges";
9
- }
10
- return parent::getTitle();
11
- }
12
- }
13
-
14
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Pdf/Tax.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ class Pb_Pbgsp_Model_Pdf_Tax extends Mage_Tax_Model_Sales_Pdf_Tax {
11
+ public function getTitle() {
12
+ $shipMethod = $this->getOrder()->getShippingMethod();
13
+ $len = strlen("pbgsp_");
14
+ if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbgsp_") {
15
+ return "Importation Charges";
16
+ }
17
+ return parent::getTitle();
18
+ }
19
+ }
20
+
21
+ ?>
app/code/local/Pb/Pbgsp/Model/Quote/Duty.php CHANGED
@@ -1,76 +1,84 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Quote_Duty extends Mage_Tax_Model_Sales_Total_Quote_Tax
4
- {
5
- /**
6
- * Discount calculation object
7
- *
8
- * @var Mage_SalesRule_Model_Validator
9
- */
10
- protected $dutyCalculated = false;
11
- protected $dutyDisplayed = false;
12
-
13
- public function __construct()
14
- {
15
- parent::__construct();
16
- }
17
-
18
- public function getDutyAndTax() {
19
- //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.getDutyAndTax');
20
- return Mage::getSingleton("customer/session")->getPbDutyAndTax();
21
- }
22
-
23
- /**
24
- * Collect address discount amount
25
- *
26
- * @param Mage_Sales_Model_Quote_Address $address
27
- * @return Mage_SalesRule_Model_Quote_Discount
28
- */
29
- public function collect(Mage_Sales_Model_Quote_Address $address)
30
- {
31
- //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.collect');
32
- parent::collect($address);
33
-
34
- if ($this->getDutyAndTax()) {
35
- $items = $this->_getAddressItems($address);
36
- if (!count($items)) {
37
- return $this;
38
- }
39
-
40
- $this->_addAmount($this->getDutyAndTax());
41
- $this->_addBaseAmount($this->getDutyAndTax());
42
- }
43
- return $this;
44
- }
45
-
46
-
47
- /**
48
- * Add discount total information to address
49
- *
50
- * @param Mage_Sales_Model_Quote_Address $address
51
- * @return Mage_SalesRule_Model_Quote_Discount
52
- */
53
- public function fetch(Mage_Sales_Model_Quote_Address $address)
54
- {
55
- //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.fetch');
56
-
57
- if ($this->getDutyAndTax()) {
58
- if($this->dutyDisplayed) {
59
- return $this;
60
- }
61
- $this->dutyDisplayed = true;
62
-
63
- $amount = $address->getTaxAmount();
64
- $title = "Duty & Taxes";
65
- Pb_Pbgsp_Model_Util::log("Add Duty & Taxes at Duty");
66
- $address->addTotal(array(
67
- 'code' => $this->getCode(),
68
- 'title' => $title,
69
- 'value' => $amount
70
- ));
71
- } else {
72
- return parent::fetch($address);
73
- }
74
- return $this;
75
- }
76
- }
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Product: Pb_Pbgsp (1.0.0)
5
+ * Packaged: 2015-06-04T15:09:31+00:00
6
+ * Last Modified: 2015-06-04T15:00:31+00:00
7
+ * File: app/code/local/Pb/Pbgsp/Model/Quote/Duty.php
8
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
9
+ */
10
+
11
+ class Pb_Pbgsp_Model_Quote_Duty extends Mage_Tax_Model_Sales_Total_Quote_Tax
12
+ {
13
+ /**
14
+ * Discount calculation object
15
+ *
16
+ * @var Mage_SalesRule_Model_Validator
17
+ */
18
+ protected $dutyCalculated = false;
19
+ protected $dutyDisplayed = false;
20
+
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+ }
25
+
26
+ public function getDutyAndTax() {
27
+ //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.getDutyAndTax');
28
+ return Mage::getSingleton("customer/session")->getPbDutyAndTax();
29
+ }
30
+
31
+ /**
32
+ * Collect address discount amount
33
+ *
34
+ * @param Mage_Sales_Model_Quote_Address $address
35
+ * @return Mage_SalesRule_Model_Quote_Discount
36
+ */
37
+ public function collect(Mage_Sales_Model_Quote_Address $address)
38
+ {
39
+ //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.collect');
40
+ parent::collect($address);
41
+
42
+ if ($this->getDutyAndTax()) {
43
+ $items = $this->_getAddressItems($address);
44
+ if (!count($items)) {
45
+ return $this;
46
+ }
47
+
48
+ $this->_addAmount($this->getDutyAndTax());
49
+ $this->_addBaseAmount($this->getDutyAndTax());
50
+ }
51
+ return $this;
52
+ }
53
+
54
+
55
+ /**
56
+ * Add discount total information to address
57
+ *
58
+ * @param Mage_Sales_Model_Quote_Address $address
59
+ * @return Mage_SalesRule_Model_Quote_Discount
60
+ */
61
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
62
+ {
63
+ //Pb_Pbgsp_Model_Util::log('Pb_Pbgsp_Model_Quote_Duty.fetch');
64
+
65
+ if ($this->getDutyAndTax()) {
66
+ if($this->dutyDisplayed) {
67
+ return $this;
68
+ }
69
+ $this->dutyDisplayed = true;
70
+
71
+ $amount = $address->getTaxAmount();
72
+ $title = "Duty & Taxes";
73
+ Pb_Pbgsp_Model_Util::log("Add Duty & Taxes at Duty");
74
+ $address->addTotal(array(
75
+ 'code' => $this->getCode(),
76
+ 'title' => $title,
77
+ 'value' => $amount
78
+ ));
79
+ } else {
80
+ return parent::fetch($address);
81
+ }
82
+ return $this;
83
+ }
84
+ }
app/code/local/Pb/Pbgsp/Model/Resource/Mysql4/Setup.php CHANGED
@@ -1,11 +1,12 @@
1
- <?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: Muhammad
5
- * Date: 3/31/2015
6
- * Time: 11:48 PM
7
- */
8
-
9
- class Pb_Pbgsp_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
10
-
 
11
  }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Resource/Mysql4/Setup.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ class Pb_Pbgsp_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
11
+
12
  }
app/code/local/Pb/Pbgsp/Model/Sales/Order/Shipment.php CHANGED
@@ -1,137 +1,138 @@
1
- <?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: Muhammad
5
- * Date: 3/27/2015
6
- * Time: 12:51 AM
7
- */
8
-
9
- class Pb_Pbgsp_Model_Sales_Order_Shipment extends Mage_Sales_Model_Order_Shipment {
10
-
11
- public function sendEmail($notifyCustomer = true, $comment = '')
12
- {
13
- if(Mage::getStoreConfig('carriers/pbgsp/suppress_domestic_tracking') != '1')
14
- return parent::sendEmail($notifyCustomer,$comment);
15
- $order = $this->getOrder();
16
- $storeId = $order->getStore()->getId();
17
-
18
- if (!Mage::helper('sales')->canSendNewShipmentEmail($storeId)) {
19
- return $this;
20
- }
21
- // Get the destination email addresses to send copies to
22
- $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
23
- $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
24
- // Check if at least one recepient is found
25
- if (!$notifyCustomer && !$copyTo) {
26
- return $this;
27
- }
28
-
29
- // Start store emulation process
30
- $appEmulation = Mage::getSingleton('core/app_emulation');
31
- $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
32
-
33
- try {
34
- // Retrieve specified view block from appropriate design package (depends on emulated store)
35
- $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
36
- ->setIsSecureMode(true);
37
- $paymentBlock->getMethod()->setStore($storeId);
38
- $paymentBlockHtml = $paymentBlock->toHtml();
39
- } catch (Exception $exception) {
40
- // Stop store emulation process
41
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
42
- throw $exception;
43
- }
44
-
45
- // Stop store emulation process
46
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
47
-
48
- // Retrieve corresponding email template id and customer name
49
- if ($order->getCustomerIsGuest()) {
50
- //$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
51
- $customerName = $order->getBillingAddress()->getName();
52
- } else {
53
- //$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
54
- $customerName = $order->getCustomerName();
55
- }
56
-
57
-
58
-
59
- $emailTemplateVariables = array(
60
- 'order' => $order,
61
- 'shipment' => $this,
62
- 'comment' => $comment,
63
- 'billing' => $order->getBillingAddress(),
64
- 'store' => Mage::app()->getStore($storeId),
65
- 'payment_html' => $paymentBlockHtml
66
-
67
-
68
- );
69
- $emailTemplate = Mage::getModel('core/email_template');
70
- // ->loadDefault('pbgsp_shipment_new');
71
- $emailTemplate = $this->_setTemplateBodyAndSubject($emailTemplate,
72
- Mage::getStoreConfig('carriers/pbgsp/custom_shipment_email_template'),
73
- Mage::getStoreConfig('carriers/pbgsp/custom_shipment_email_subject'));
74
- $emailTemplate->setSenderEmail(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
75
- $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
76
- //Pb_Pbgsp_Model_Util::log($processedTemplate);
77
- //$emailTemplate->send($order->getCustomerEmail(), $customerName,$emailTemplateVariables);
78
- //Pb_Pbgsp_Model_Util::log('Email subject'. $emailTemplate->getTemplateSubject());
79
- //Pb_Pbgsp_Model_Util::log('Processed Email Subject is'. $emailTemplate->getProcessedTemplateSubject($emailTemplateVariables));
80
- $fromName = Mage::getStoreConfig('trans_email/ident_' . Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId) . '/name', $storeId);
81
- $fromEmail = Mage::getStoreConfig('trans_email/ident_' . Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId) . '/email', $storeId);
82
- $mail = Mage::getModel('core/email')
83
- ->setToName($customerName)
84
- ->setToEmail($order->getCustomerEmail())
85
- ->setBody($processedTemplate)
86
- ->setSubject($emailTemplate->getProcessedTemplateSubject($emailTemplateVariables))
87
- ->setFromEmail($fromEmail)
88
- ->setFromName($fromName)
89
- ->setType('html');
90
- try{
91
-
92
- Pb_Pbgsp_Model_Util::log("Form email $fromEmail from name $fromName");
93
- $mail->send();
94
- //Pb_Pbgsp_Model_Util::log("Email sent to");
95
- //Pb_Pbgsp_Model_Util::log($order->getCustomerEmail());
96
- }
97
- catch(Exception $error)
98
- {
99
- Pb_Pbgsp_Model_Util::log("Error sending shipment email". $error->getMessage());
100
- Pb_Pbgsp_Model_Util::log($error->getTraceAsString());
101
-
102
- }
103
-
104
- return $this;
105
- }
106
- private function _setTemplateBodyAndSubject($template,$body,$subject)
107
- {
108
-
109
- $template->setTemplateType( Mage_Core_Model_Template::TYPE_HTML);
110
-
111
- $templateText = $body;
112
- $template->setTemplateSubject($subject);
113
-
114
-
115
- if (preg_match('/<!--@vars\s*((?:.)*?)\s*@-->/us', $templateText, $matches)) {
116
- $template->setData('orig_template_variables', str_replace("\n", '', $matches[1]));
117
- $templateText = str_replace($matches[0], '', $templateText);
118
- }
119
-
120
- if (preg_match('/<!--@styles\s*(.*?)\s*@-->/s', $templateText, $matches)) {
121
- $this->setTemplateStyles($matches[1]);
122
- $templateText = str_replace($matches[0], '', $templateText);
123
- }
124
-
125
- /**
126
- * Remove comment lines
127
- */
128
- $templateText = preg_replace('#\{\*.*\*\}#suU', '', $templateText);
129
-
130
- $template->setTemplateText($templateText);
131
- // $this->setId($templateId);
132
-
133
- return $template;
134
- }
135
-
136
-
 
137
  }
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Sales/Order/Shipment.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+ class Pb_Pbgsp_Model_Sales_Order_Shipment extends Mage_Sales_Model_Order_Shipment {
11
+
12
+ public function sendEmail($notifyCustomer = true, $comment = '')
13
+ {
14
+ if(Mage::getStoreConfig('carriers/pbgsp/suppress_domestic_tracking') != '1')
15
+ return parent::sendEmail($notifyCustomer,$comment);
16
+ $order = $this->getOrder();
17
+ $storeId = $order->getStore()->getId();
18
+
19
+ if (!Mage::helper('sales')->canSendNewShipmentEmail($storeId)) {
20
+ return $this;
21
+ }
22
+ // Get the destination email addresses to send copies to
23
+ $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
24
+ $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
25
+ // Check if at least one recepient is found
26
+ if (!$notifyCustomer && !$copyTo) {
27
+ return $this;
28
+ }
29
+
30
+ // Start store emulation process
31
+ $appEmulation = Mage::getSingleton('core/app_emulation');
32
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
33
+
34
+ try {
35
+ // Retrieve specified view block from appropriate design package (depends on emulated store)
36
+ $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
37
+ ->setIsSecureMode(true);
38
+ $paymentBlock->getMethod()->setStore($storeId);
39
+ $paymentBlockHtml = $paymentBlock->toHtml();
40
+ } catch (Exception $exception) {
41
+ // Stop store emulation process
42
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
43
+ throw $exception;
44
+ }
45
+
46
+ // Stop store emulation process
47
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
48
+
49
+ // Retrieve corresponding email template id and customer name
50
+ if ($order->getCustomerIsGuest()) {
51
+ //$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
52
+ $customerName = $order->getBillingAddress()->getName();
53
+ } else {
54
+ //$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
55
+ $customerName = $order->getCustomerName();
56
+ }
57
+
58
+
59
+
60
+ $emailTemplateVariables = array(
61
+ 'order' => $order,
62
+ 'shipment' => $this,
63
+ 'comment' => $comment,
64
+ 'billing' => $order->getBillingAddress(),
65
+ 'store' => Mage::app()->getStore($storeId),
66
+ 'payment_html' => $paymentBlockHtml
67
+
68
+
69
+ );
70
+ $emailTemplate = Mage::getModel('core/email_template');
71
+ // ->loadDefault('pbgsp_shipment_new');
72
+ $emailTemplate = $this->_setTemplateBodyAndSubject($emailTemplate,
73
+ Mage::getStoreConfig('carriers/pbgsp/custom_shipment_email_template'),
74
+ Mage::getStoreConfig('carriers/pbgsp/custom_shipment_email_subject'));
75
+ $emailTemplate->setSenderEmail(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
76
+ $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
77
+ //Pb_Pbgsp_Model_Util::log($processedTemplate);
78
+ //$emailTemplate->send($order->getCustomerEmail(), $customerName,$emailTemplateVariables);
79
+ //Pb_Pbgsp_Model_Util::log('Email subject'. $emailTemplate->getTemplateSubject());
80
+ //Pb_Pbgsp_Model_Util::log('Processed Email Subject is'. $emailTemplate->getProcessedTemplateSubject($emailTemplateVariables));
81
+ $fromName = Mage::getStoreConfig('trans_email/ident_' . Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId) . '/name', $storeId);
82
+ $fromEmail = Mage::getStoreConfig('trans_email/ident_' . Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId) . '/email', $storeId);
83
+ $mail = Mage::getModel('core/email')
84
+ ->setToName($customerName)
85
+ ->setToEmail($order->getCustomerEmail())
86
+ ->setBody($processedTemplate)
87
+ ->setSubject($emailTemplate->getProcessedTemplateSubject($emailTemplateVariables))
88
+ ->setFromEmail($fromEmail)
89
+ ->setFromName($fromName)
90
+ ->setType('html');
91
+ try{
92
+
93
+ Pb_Pbgsp_Model_Util::log("Form email $fromEmail from name $fromName");
94
+ $mail->send();
95
+ //Pb_Pbgsp_Model_Util::log("Email sent to");
96
+ //Pb_Pbgsp_Model_Util::log($order->getCustomerEmail());
97
+ }
98
+ catch(Exception $error)
99
+ {
100
+ Pb_Pbgsp_Model_Util::log("Error sending shipment email". $error->getMessage());
101
+ Pb_Pbgsp_Model_Util::log($error->getTraceAsString());
102
+
103
+ }
104
+
105
+ return $this;
106
+ }
107
+ private function _setTemplateBodyAndSubject($template,$body,$subject)
108
+ {
109
+
110
+ $template->setTemplateType( Mage_Core_Model_Template::TYPE_HTML);
111
+
112
+ $templateText = $body;
113
+ $template->setTemplateSubject($subject);
114
+
115
+
116
+ if (preg_match('/<!--@vars\s*((?:.)*?)\s*@-->/us', $templateText, $matches)) {
117
+ $template->setData('orig_template_variables', str_replace("\n", '', $matches[1]));
118
+ $templateText = str_replace($matches[0], '', $templateText);
119
+ }
120
+
121
+ if (preg_match('/<!--@styles\s*(.*?)\s*@-->/s', $templateText, $matches)) {
122
+ $this->setTemplateStyles($matches[1]);
123
+ $templateText = str_replace($matches[0], '', $templateText);
124
+ }
125
+
126
+ /**
127
+ * Remove comment lines
128
+ */
129
+ $templateText = preg_replace('#\{\*.*\*\}#suU', '', $templateText);
130
+
131
+ $template->setTemplateText($templateText);
132
+ // $this->setId($templateId);
133
+
134
+ return $template;
135
+ }
136
+
137
+
138
  }
app/code/local/Pb/Pbgsp/Model/Util.php CHANGED
@@ -1,23 +1,29 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Util {
4
-
5
- const FILE_NAME = 'pbgsp.log';
6
- public static function log($message) {
7
- if( Mage::getStoreConfig('carriers/pbgsp/separate_log_file'))
8
- Mage::log($message,null,self::FILE_NAME);
9
- else
10
- Mage::log($message);
11
- }
12
- public static function logException($e) {
13
- /* @var Exception $e */
14
- if( Mage::getStoreConfig('carriers/pbgsp/separate_log_file')) {
15
- Mage::log($e->getMessage(),null,self::FILE_NAME);
16
- Mage::log($e->getTraceAsString(),null,self::FILE_NAME);
17
- }
18
- else
19
- Mage::logException($e);
20
- }
21
- }
22
-
23
- ?>
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Util.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Util {
10
+
11
+ const FILE_NAME = 'pbgsp.log';
12
+ public static function log($message) {
13
+ if( Mage::getStoreConfig('carriers/pbgsp/separate_log_file'))
14
+ Mage::log($message,null,self::FILE_NAME);
15
+ else
16
+ Mage::log($message);
17
+ }
18
+ public static function logException($e) {
19
+ /* @var Exception $e */
20
+ if( Mage::getStoreConfig('carriers/pbgsp/separate_log_file')) {
21
+ Mage::log($e->getMessage(),null,self::FILE_NAME);
22
+ Mage::log($e->getTraceAsString(),null,self::FILE_NAME);
23
+ }
24
+ else
25
+ Mage::logException($e);
26
+ }
27
+ }
28
+
29
+ ?>
app/code/local/Pb/Pbgsp/Model/Variable.php CHANGED
@@ -1,11 +1,17 @@
1
- <?php
2
-
3
- class Pb_Pbgsp_Model_Variable extends Mage_Core_Model_Abstract {
4
- public function _construct()
5
- {
6
- parent::_construct();
7
- $this->_init('pb_pbgsp/variable');
8
- }
9
- }
10
-
11
- ?>
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/Model/Variable.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+ class Pb_Pbgsp_Model_Variable extends Mage_Core_Model_Abstract {
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('pb_pbgsp/variable');
14
+ }
15
+ }
16
+
17
+ ?>
app/code/local/Pb/Pbgsp/data/pb_pbgsp_setup/data-install-1.0.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-05-06T18:09:31+00:00
5
+ * Last Modified: 2015-05-06T18:09:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/sql/pbgsp_setup/mysql4-install-1.0.0.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+
11
+ Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
12
+ $categories = Mage::getModel('catalog/category')
13
+ ->getCollection();
14
+ foreach($categories as $category) {
15
+ $category->setPbPbgspUploadActive(1);
16
+ $category->save();
17
+ }
18
+
19
+ ?>
app/code/local/Pb/Pbgsp/etc/config.xml CHANGED
@@ -1,491 +1,509 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Pb_Pbgsp>
5
- <version>1.0.0</version>
6
- </Pb_Pbgsp>
7
- </modules>
8
- <global>
9
- <!--<template>-->
10
- <!--<email>-->
11
- <!--<sales_email_pb_shipment_template>-->
12
- <!--<label>Pitney Bowes Custom Shipment Email</label>-->
13
- <!--<file>pbgsp_shipment_new.html</file>-->
14
- <!--<type>html</type>-->
15
- <!--</sales_email_pb_shipment_template>-->
16
- <!--</email>-->
17
- <!--</template>-->
18
- <blocks>
19
- <PB_Pbgsp>
20
- <class>Pb_Pbgsp_Block</class>
21
- </PB_Pbgsp>
22
- <sales>
23
- <rewrite>
24
- <order_totals>Pb_Pbgsp_Block_Sales_Order_Totals</order_totals>
25
- <order_invoice_totals>Pb_Pbgsp_Block_Sales_Order_Invoice_Totals</order_invoice_totals>
26
-
27
- </rewrite>
28
- </sales>
29
- <adminhtml>
30
- <rewrite>
31
- <sales_order_totals>Pb_Pbgsp_Block_Adminhtml_Sales_Order_Totals</sales_order_totals>
32
- <sales_order_invoice_totals>Pb_Pbgsp_Block_Adminhtml_Sales_Order_Invoice_Totals</sales_order_invoice_totals>
33
-
34
- </rewrite>
35
- </adminhtml>
36
- <checkout>
37
- <rewrite>
38
- <onepage_shipping_method_available>Pb_Pbgsp_Block_Checkout_Shipping_Method_Available</onepage_shipping_method_available>
39
- </rewrite>
40
- </checkout>
41
- </blocks>
42
- <models>
43
- <pb_pbgsp>
44
- <class>Pb_Pbgsp_Model</class>
45
- <resourceModel>pb_pbgsp_mysql4</resourceModel>
46
- </pb_pbgsp>
47
- <pb_pbgsp_mysql4>
48
- <class>Pb_Pbgsp_Model_Mysql4</class>
49
- <entities>
50
- <variable>
51
- <table>pbgsp_variable</table>
52
- </variable>
53
- <ordernumber>
54
- <table>pbgsp_ordernumber</table>
55
- </ordernumber>
56
- <inboundparcel>
57
- <table>pbgsp_inbound_parcel</table>
58
- </inboundparcel>
59
- </entities>
60
- </pb_pbgsp_mysql4>
61
- <sales>
62
- <rewrite>
63
- <order_invoice_total_tax>Pb_Pbgsp_Model_Invoice_Duty</order_invoice_total_tax>
64
- <order_creditmemo_total_tax>Pb_Pbgsp_Model_Creditmemo_Duty</order_creditmemo_total_tax>
65
- <order_shipment>Pb_Pbgsp_Model_Sales_Order_Shipment</order_shipment>
66
- </rewrite>
67
- </sales>
68
- </models>
69
- <resources>
70
- <pbgsp_setup>
71
- <setup>
72
- <module>Pb_Pbgsp</module>
73
- <class>Pb_Pbgsp_Model_Resource_Mysql4_Setup</class>
74
- </setup>
75
- <connection>
76
- <use>core_setup</use>
77
- </connection>
78
- </pbgsp_setup>
79
- <pb_pbgsp_write>
80
- <connection>
81
- <use>core_write</use>
82
- </connection>
83
- </pb_pbgsp_write>
84
- <pb_pbgsp_read>
85
- <connection>
86
- <use>core_read</use>
87
- </connection>
88
- </pb_pbgsp_read>
89
- </resources>
90
- <events>
91
- <!--<checkout_submit_all_after>&lt;!&ndash; added by Kamran 7/2/2014 &ndash;&gt;-->
92
- <!--<observers>-->
93
- <!--<Pb_Pbgsp_Model_CheckoutSubmitAllAfter>-->
94
- <!--<type>model</type>-->
95
- <!--<class>pb_pbgsp/observer</class>-->
96
- <!--<method>createOrderAdminAfter</method>-->
97
- <!--</Pb_Pbgsp_Model_CheckoutSubmitAllAfter>-->
98
- <!--</observers>-->
99
- <!--</checkout_submit_all_after>-->
100
- <core_block_abstract_to_html_after>
101
- <observers>
102
- <Pb_Pbgsp_Model_OrderView>
103
- <type>model</type>
104
- <class>pb_pbgsp/observer</class>
105
- <method>modifyOrderView</method>
106
- </Pb_Pbgsp_Model_OrderView>
107
- </observers>
108
- </core_block_abstract_to_html_after>
109
- <checkout_controller_onepage_save_shipping_method>
110
- <observers>
111
- <Pb_Pbgsp_Model_SaveShippingOne>
112
- <type>model</type>
113
- <class>pb_pbgsp/observer</class>
114
- <method>saveShippingMethod</method>
115
- </Pb_Pbgsp_Model_SaveShippingOne>
116
- </observers>
117
- </checkout_controller_onepage_save_shipping_method>
118
- <checkout_onepage_controller_success_action>
119
- <observers>
120
- <Pb_Pbgsp_Model_CheckoutCompleteOne>
121
- <type>model</type>
122
- <class>pb_pbgsp/observer</class>
123
- <method>createPbOrder</method>
124
- </Pb_Pbgsp_Model_CheckoutCompleteOne>
125
- </observers>
126
- </checkout_onepage_controller_success_action>
127
- <controller_action_postdispatch_checkout_cart_estimateUpdatePost>
128
- <observers>
129
- <Pb_Pbgsp_Estimated_Shipping>
130
- <type>model</type>
131
- <class>pb_pbgsp/observer</class>
132
- <method>addDutiesOnEstimation</method>
133
- </Pb_Pbgsp_Estimated_Shipping>
134
- </observers>
135
- </controller_action_postdispatch_checkout_cart_estimateUpdatePost>
136
- </events>
137
- <sales>
138
- <quote>
139
- <totals>
140
- <tax>
141
- <class>Pb_Pbgsp_Model_Quote_Duty</class>
142
- <before>grand_total</before>
143
- <after>shipping</after>
144
- </tax>
145
- </totals>
146
- </quote>
147
- </sales>
148
- <pdf>
149
- <totals>
150
- <tax translate="title">
151
- <title>Tax</title>
152
- <source_field>tax_amount</source_field>
153
- <model>pb_pbgsp/pdf_tax</model>
154
- <font_size>7</font_size>
155
- <display_zero>0</display_zero>
156
- <sort_order>300</sort_order>
157
- </tax>
158
- </totals>
159
- </pdf>
160
-
161
- </global>
162
- <resources>
163
- <sales_setup>
164
- <setup>
165
- <module>Pb_Pbgsp</module>
166
- <class>Pb_Pbgsp_Model_Entity_Setup</class>
167
- </setup>
168
- </sales_setup>
169
- </resources>
170
-
171
- <!--<frontend>-->
172
- <!--<layout>-->
173
- <!--<updates>-->
174
- <!--<pbcheckout>-->
175
- <!--<file>pbcheckout.xml</file>-->
176
- <!--</pbcheckout>-->
177
- <!--</updates>-->
178
- <!--</layout>-->
179
- <!--<routers>-->
180
- <!--<Pb_Pbgsp>-->
181
- <!--<use>standard</use>-->
182
- <!--<args>-->
183
- <!--<module>Pb_Pbgsp</module>-->
184
- <!--<frontName>pbgsp</frontName>-->
185
- <!--&lt;!&ndash; loads ../controller/IndexController in http://..../magento/index.php/testController &ndash;&gt;-->
186
- <!--</args>-->
187
- <!--</Pb_Pbgsp>-->
188
- <!--</routers>-->
189
- <!--<translate>-->
190
- <!--<modules>-->
191
- <!--<translations>-->
192
- <!--<files>-->
193
- <!--<default>Pb_Pbgsp.csv</default>-->
194
- <!--</files>-->
195
- <!--</translations>-->
196
- <!--</modules>-->
197
- <!--</translate>-->
198
- <!--</frontend>-->
199
-
200
- <default>
201
- <carriers>
202
- <pbgsp>
203
- <active>1</active>
204
- <sallowspecific>0</sallowspecific>
205
- <model>Pb_Pbgsp_Model_Carrier_ShippingMethod</model>
206
- <specificerrmsg>
207
- This shipping method is currently unavailable.
208
- If you would like to ship using this shipping
209
- method, please contact us.
210
- </specificerrmsg>
211
- <handling_type>F</handling_type>
212
- <catalog_diff>1</catalog_diff>
213
- <catalog_full>1</catalog_full>
214
- <catalog_size>10000</catalog_size>
215
- <catalog_encryption_enabled>0</catalog_encryption_enabled>
216
- <asn_generation_enabled>1</asn_generation_enabled>
217
- <suppress_domestic_tracking>1</suppress_domestic_tracking>
218
- <custom_shipment_email_subject><![CDATA[{{var store.getFrontendName()}}: Shipment confirmation for Order # {{var order.increment_id}}]]>
219
- </custom_shipment_email_subject>
220
- <custom_shipment_email_template><![CDATA[<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Hello, {{htmlescape var=$order.getCustomerName()}}</h1>
221
- <p style="font-size:12px; line-height:16px; margin:0;">
222
- Thank you for your order from {{var store.getFrontendName()}}.
223
- You can check the status of your order by <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">logging into your account</a>.
224
-
225
- </p>
226
- <p style="font-size:12px; line-height:16px; margin:0;">
227
- Your shipping confirmation is below. Thank you again for your business.
228
- </p>
229
-
230
- <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} has been shipped from local warehouse to international shipment hub from where it will be shipped to your country.</h2>
231
-
232
- ]]>
233
- </custom_shipment_email_template>
234
- <separate_log_file>0</separate_log_file>
235
-
236
- <shipping_services>
237
- <POSTAL_PRIORITY>
238
- <title>Standard</title>
239
- <enabled>0</enabled>
240
- </POSTAL_PRIORITY>
241
- <FEDEX_ECONOMY>
242
- <title>Express</title>
243
- <enabled>1</enabled>
244
- </FEDEX_ECONOMY>
245
- <FEDEX_PRIORITY>
246
- <title>Express Plus</title>
247
- <enabled>1</enabled>
248
- </FEDEX_PRIORITY>
249
- <AE_STANDARD>
250
- <title>Premier</title>
251
- <enabled>1</enabled>
252
- </AE_STANDARD>
253
- <AU_STANDARD>
254
- <title>Premier</title>
255
- <enabled>1</enabled>
256
- </AU_STANDARD>
257
- <CN_STANDARD>
258
- <title>Premier</title>
259
- <enabled>1</enabled>
260
- </CN_STANDARD>
261
- <CPC_EXPRESS>
262
- <title>Premier Plus</title>
263
- <enabled>1</enabled>
264
- </CPC_EXPRESS>
265
- <CPC_STANDARD>
266
- <title>Premier</title>
267
- <enabled>1</enabled>
268
- </CPC_STANDARD>
269
- <EU_STANDARD>
270
- <title>Premier</title>
271
- <enabled>1</enabled>
272
- </EU_STANDARD>
273
- <HK_STANDARD>
274
- <title>Premier</title>
275
- <enabled>1</enabled>
276
- </HK_STANDARD>
277
- <KR_STANDARD>
278
- <title>Premier</title>
279
- <enabled>1</enabled>
280
- </KR_STANDARD>
281
- <NZ_STANDARD>
282
- <title>Premier</title>
283
- <enabled>1</enabled>
284
- </NZ_STANDARD>
285
- <PH_STANDARD>
286
- <title>Premier</title>
287
- <enabled>1</enabled>
288
- </PH_STANDARD>
289
- <SG_STANDARD>
290
- <title>Premier</title>
291
- <enabled>1</enabled>
292
- </SG_STANDARD>
293
- <TH_STANDARD>
294
- <title>Premier</title>
295
- <enabled>1</enabled>
296
- </TH_STANDARD>
297
- <TW_STANDARD>
298
- <title>Premier</title>
299
- <enabled>1</enabled>
300
- </TW_STANDARD>
301
- </shipping_services>
302
- <error_messages>
303
- <_1005001>
304
- <display>The shipping address is invalid.</display>
305
- </_1005001>
306
- <_1005002>
307
- <display>The consignee information is invalid.</display>
308
- </_1005002>
309
- <_1005003>
310
- <display>The COP transportation information is invalid.</display>
311
- </_1005003>
312
- <_1005004>
313
- <display>The requested return currency is invalid.</display>
314
- </_1005004>
315
- <_1005005>
316
- <display>The request currency is not supported for the target country.</display>
317
- </_1005005>
318
- <_1005006>
319
- <display>The order cannot be shipped by the method selected.</display>
320
- </_1005006>
321
- <_1005007>
322
- <display>The order value has exceeded the allowed value.</display>
323
- </_1005007>
324
- <_1005008>
325
- <display>Invalid fields in parcels.</display>
326
- </_1005008>
327
- <_1005009>
328
- <display>Invalid fields in commoditySources.</display>
329
- </_1005009>
330
- <_1005010>
331
- <display>There are errors at the Quote Line Level.</display>
332
- </_1005010>
333
- <_1005011>
334
- <display>There are errors at the Quote Item Level.</display>
335
- </_1005011>
336
- <_1005012>
337
- <display>The order exceeded the weight limit.</display>
338
- </_1005012>
339
- <_1005013>
340
- <display>The shipping address has missing fields.</display>
341
- </_1005013>
342
- <_1005014>
343
- <display>Missing fields in basket.</display>
344
- </_1005014>
345
- <_1005015>
346
- <display>Invalid fields in basket.</display>
347
- </_1005015>
348
- <_1005016>
349
- <display>The consignee information is missing.</display>
350
- </_1005016>
351
- <_1005017>
352
- <display>The COP transportation information is missing.</display>
353
- </_1005017>
354
- <_1005018>
355
- <display>Shipping Speed unavailable.</display>
356
- </_1005018>
357
- <_1005018>
358
- <display>Shipping Speed unavailable.</display>
359
- </_1005018>
360
- <_1005019>
361
- <display>Missing Basket.</display>
362
- </_1005019>
363
- <_1005020>
364
- <display>Missing Parcel Fields.</display>
365
- </_1005020>
366
- <_1005021>
367
- <display>Missing fields in the basket commodity source.</display>
368
- </_1005021>
369
- <_1005022>
370
- <display>Invalid Parcel Fields.</display>
371
- </_1005022>
372
- <_1006001>
373
- <display>The commodity was invalid.</display>
374
- </_1006001>
375
- <_1006002>
376
- <display>The commodity is too large to ship (length, width or height).</display>
377
- </_1006002>
378
- <_1006003>
379
- <display>The commodity cannot be shipped to the COD.</display>
380
- </_1006003>
381
- <_1006004>
382
- <display>The commodity has a negative price.</display>
383
- </_1006004>
384
- <_1006005>
385
- <display>The commodity’s price was too low and did not have a dutiable value.</display>
386
- </_1006005>
387
- <_1006006>
388
- <display>The item price exceeds maximum.</display>
389
- </_1006006>
390
- <_1006007>
391
- <display>Item weight exceeds maximum.</display>
392
- </_1006007>
393
- <_1006008>
394
- <display>Invalid commodity rated data. Commodity cannot be shipped at this time. This is an internal error and should be raised to PB immediately. .</display>
395
- </_1006008>
396
- <_1006009>
397
- <display>The Commodity is restricted for this Country of Destination.</display>
398
- </_1006009>
399
- <_10060010>
400
- <display>Commodity cannot be quoted.</display>
401
- </_10060010>
402
- <_10060011>
403
- <display>Commodity cannot shipped to the address specified.</display>
404
- </_10060011>
405
- <_1007001>
406
- <display>Order value exceeded on this line.</display>
407
- </_1007001>
408
- <_1007002>
409
- <display>Line too large to ship (length, width or height of the shipping box).</display>
410
- </_1007002>
411
- <_1007003>
412
- <display>The quantity is invalid or missing.</display>
413
- </_1007003>
414
- <_1007004>
415
- <display>Weight Value exceeded on this line.</display>
416
- </_1007004>
417
- <_1007005>
418
- <display>Errors in the kitContents.</display>
419
- </_1007005>
420
- <_1007006>
421
- <display>Missing fields in basket line.</display>
422
- </_1007006>
423
- <_1007007>
424
- <display>Invalid fields in basket line.</display>
425
- </_1007007>
426
- <_1007008>
427
- <display>Quantity exceeded for Country of Destination.</display>
428
- </_1007008>
429
- </error_messages>
430
- </pbgsp>
431
- </carriers>
432
- </default>
433
-
434
- <!-- Please modify this part for CRON JOB
435
- For more information on Magento Cron Job, please visit the following url:
436
- http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#built-in_cron_jobs
437
- -->
438
- <crontab>
439
- <jobs>
440
- <pb_pbgsp>
441
- <schedule>
442
- <cron_expr>30 * * * *</cron_expr>
443
- </schedule>
444
- <run>
445
- <model>pb_pbgsp/catalog_cron::catalogSync</model>
446
- </run>
447
- </pb_pbgsp>
448
- <pb_notifications>
449
- <schedule>
450
- <cron_expr>20 * * * *</cron_expr>
451
- </schedule>
452
- <run>
453
- <model>pb_pbgsp/catalog_cron::processStatusNotifications</model>
454
- </run>
455
- </pb_notifications>
456
- </jobs>
457
- </crontab>
458
- <adminhtml>
459
- <events>
460
- <!--<sales_order_save_commit_after>-->
461
- <!--<observers>-->
462
- <!--<Pb_Pbgsp_CreateParcel>-->
463
- <!--<type>model</type>-->
464
- <!--<class>pb_pbgsp/observer</class>-->
465
- <!--<method>generateInboundParcelPreAdvice</method>-->
466
- <!--</Pb_Pbgsp_CreateParcel>-->
467
- <!--</observers>-->
468
- <!--</sales_order_save_commit_after>-->
469
- <sales_order_shipment_save_after>
470
- <observers>
471
- <Pb_Pbgsp_CreateParcel>
472
- <type>model</type>
473
- <class>pb_pbgsp/observer</class>
474
- <method>generateInboundParcelPreAdvice</method>
475
- </Pb_Pbgsp_CreateParcel>
476
- </observers>
477
- </sales_order_shipment_save_after>
478
- </events>
479
- <!--<translate>-->
480
- <!--<modules>-->
481
- <!--<translations>-->
482
- <!--<files>-->
483
- <!--<default>Pb_Pbgsp.csv</default>-->
484
- <!--</files>-->
485
- <!--</translations>-->
486
- <!--</modules>-->
487
- <!--</translate>-->
488
- </adminhtml>
489
-
490
- </config>
491
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Pb_Pbgsp>
5
+ <version>1.0.0</version>
6
+ </Pb_Pbgsp>
7
+ </modules>
8
+ <global>
9
+ <!--<template>-->
10
+ <!--<email>-->
11
+ <!--<sales_email_pb_shipment_template>-->
12
+ <!--<label>Pitney Bowes Custom Shipment Email</label>-->
13
+ <!--<file>pbgsp_shipment_new.html</file>-->
14
+ <!--<type>html</type>-->
15
+ <!--</sales_email_pb_shipment_template>-->
16
+ <!--</email>-->
17
+ <!--</template>-->
18
+ <blocks>
19
+ <PB_Pbgsp>
20
+ <class>Pb_Pbgsp_Block</class>
21
+ </PB_Pbgsp>
22
+ <sales>
23
+ <rewrite>
24
+ <order_totals>Pb_Pbgsp_Block_Sales_Order_Totals</order_totals>
25
+ <order_invoice_totals>Pb_Pbgsp_Block_Sales_Order_Invoice_Totals</order_invoice_totals>
26
+
27
+ </rewrite>
28
+ </sales>
29
+ <adminhtml>
30
+ <rewrite>
31
+ <sales_order_totals>Pb_Pbgsp_Block_Adminhtml_Sales_Order_Totals</sales_order_totals>
32
+ <sales_order_invoice_totals>Pb_Pbgsp_Block_Adminhtml_Sales_Order_Invoice_Totals</sales_order_invoice_totals>
33
+
34
+ </rewrite>
35
+ </adminhtml>
36
+ <checkout>
37
+ <rewrite>
38
+ <onepage_shipping_method_available>Pb_Pbgsp_Block_Checkout_Shipping_Method_Available</onepage_shipping_method_available>
39
+ </rewrite>
40
+ </checkout>
41
+ </blocks>
42
+ <models>
43
+ <pb_pbgsp>
44
+ <class>Pb_Pbgsp_Model</class>
45
+ <resourceModel>pb_pbgsp_mysql4</resourceModel>
46
+ </pb_pbgsp>
47
+ <pb_pbgsp_mysql4>
48
+ <class>Pb_Pbgsp_Model_Mysql4</class>
49
+ <entities>
50
+ <variable>
51
+ <table>pbgsp_variable</table>
52
+ </variable>
53
+ <ordernumber>
54
+ <table>pbgsp_ordernumber</table>
55
+ </ordernumber>
56
+ <inboundparcel>
57
+ <table>pbgsp_inbound_parcel</table>
58
+ </inboundparcel>
59
+ </entities>
60
+ </pb_pbgsp_mysql4>
61
+ <sales>
62
+ <rewrite>
63
+ <order_invoice_total_tax>Pb_Pbgsp_Model_Invoice_Duty</order_invoice_total_tax>
64
+ <order_creditmemo_total_tax>Pb_Pbgsp_Model_Creditmemo_Duty</order_creditmemo_total_tax>
65
+ <order_shipment>Pb_Pbgsp_Model_Sales_Order_Shipment</order_shipment>
66
+ </rewrite>
67
+ </sales>
68
+ </models>
69
+ <resources>
70
+ <pbgsp_setup>
71
+ <setup>
72
+ <module>Pb_Pbgsp</module>
73
+ <class>Pb_Pbgsp_Model_Resource_Mysql4_Setup</class>
74
+ </setup>
75
+ <connection>
76
+ <use>core_setup</use>
77
+ </connection>
78
+ </pbgsp_setup>
79
+ <pb_pbgsp_write>
80
+ <connection>
81
+ <use>core_write</use>
82
+ </connection>
83
+ </pb_pbgsp_write>
84
+ <pb_pbgsp_read>
85
+ <connection>
86
+ <use>core_read</use>
87
+ </connection>
88
+ </pb_pbgsp_read>
89
+ </resources>
90
+ <events>
91
+ <!--<checkout_submit_all_after>&lt;!&ndash; added by Kamran 7/2/2014 &ndash;&gt;-->
92
+ <!--<observers>-->
93
+ <!--<Pb_Pbgsp_Model_CheckoutSubmitAllAfter>-->
94
+ <!--<type>model</type>-->
95
+ <!--<class>pb_pbgsp/observer</class>-->
96
+ <!--<method>createOrderAdminAfter</method>-->
97
+ <!--</Pb_Pbgsp_Model_CheckoutSubmitAllAfter>-->
98
+ <!--</observers>-->
99
+ <!--</checkout_submit_all_after>-->
100
+ <core_block_abstract_to_html_after>
101
+ <observers>
102
+ <Pb_Pbgsp_Model_OrderView>
103
+ <type>model</type>
104
+ <class>pb_pbgsp/observer</class>
105
+ <method>modifyOrderView</method>
106
+ </Pb_Pbgsp_Model_OrderView>
107
+ </observers>
108
+ </core_block_abstract_to_html_after>
109
+ <checkout_controller_onepage_save_shipping_method>
110
+ <observers>
111
+ <Pb_Pbgsp_Model_SaveShippingOne>
112
+ <type>model</type>
113
+ <class>pb_pbgsp/observer</class>
114
+ <method>saveShippingMethod</method>
115
+ </Pb_Pbgsp_Model_SaveShippingOne>
116
+ </observers>
117
+ </checkout_controller_onepage_save_shipping_method>
118
+ <checkout_onepage_controller_success_action>
119
+ <observers>
120
+ <Pb_Pbgsp_Model_CheckoutCompleteOne>
121
+ <type>model</type>
122
+ <class>pb_pbgsp/observer</class>
123
+ <method>createPbOrder</method>
124
+ </Pb_Pbgsp_Model_CheckoutCompleteOne>
125
+ </observers>
126
+ </checkout_onepage_controller_success_action>
127
+ <controller_action_postdispatch_checkout_cart_estimateUpdatePost>
128
+ <observers>
129
+ <Pb_Pbgsp_Estimated_Shipping>
130
+ <type>model</type>
131
+ <class>pb_pbgsp/observer</class>
132
+ <method>addDutiesOnEstimation</method>
133
+ </Pb_Pbgsp_Estimated_Shipping>
134
+ </observers>
135
+ </controller_action_postdispatch_checkout_cart_estimateUpdatePost>
136
+ <catalog_product_load_after>
137
+ <observers>
138
+ <Pb_Pbgsp_Product_Last_Export>
139
+ <type>model</type>
140
+ <class>pb_pbgsp/observer</class>
141
+ <method>productLoadAfter</method>
142
+ </Pb_Pbgsp_Product_Last_Export>
143
+ </observers>
144
+ </catalog_product_load_after>
145
+ <catalog_category_load_after>
146
+ <observers>
147
+ <Pb_Pbgsp_Product_Last_Export>
148
+ <type>model</type>
149
+ <class>pb_pbgsp/observer</class>
150
+ <method>categoryLoadAfter</method>
151
+ </Pb_Pbgsp_Product_Last_Export>
152
+ </observers>
153
+ </catalog_category_load_after>
154
+ </events>
155
+ <sales>
156
+ <quote>
157
+ <totals>
158
+ <tax>
159
+ <class>Pb_Pbgsp_Model_Quote_Duty</class>
160
+ <before>grand_total</before>
161
+ <after>shipping</after>
162
+ </tax>
163
+ </totals>
164
+ </quote>
165
+ </sales>
166
+ <pdf>
167
+ <totals>
168
+ <tax translate="title">
169
+ <title>Tax</title>
170
+ <source_field>tax_amount</source_field>
171
+ <model>pb_pbgsp/pdf_tax</model>
172
+ <font_size>7</font_size>
173
+ <display_zero>0</display_zero>
174
+ <sort_order>300</sort_order>
175
+ </tax>
176
+ </totals>
177
+ </pdf>
178
+
179
+ </global>
180
+ <resources>
181
+ <sales_setup>
182
+ <setup>
183
+ <module>Pb_Pbgsp</module>
184
+ <class>Pb_Pbgsp_Model_Entity_Setup</class>
185
+ </setup>
186
+ </sales_setup>
187
+ </resources>
188
+
189
+ <!--<frontend>-->
190
+ <!--<layout>-->
191
+ <!--<updates>-->
192
+ <!--<pbcheckout>-->
193
+ <!--<file>pbcheckout.xml</file>-->
194
+ <!--</pbcheckout>-->
195
+ <!--</updates>-->
196
+ <!--</layout>-->
197
+ <!--<routers>-->
198
+ <!--<Pb_Pbgsp>-->
199
+ <!--<use>standard</use>-->
200
+ <!--<args>-->
201
+ <!--<module>Pb_Pbgsp</module>-->
202
+ <!--<frontName>pbgsp</frontName>-->
203
+ <!--&lt;!&ndash; loads ../controller/IndexController in http://..../magento/index.php/testController &ndash;&gt;-->
204
+ <!--</args>-->
205
+ <!--</Pb_Pbgsp>-->
206
+ <!--</routers>-->
207
+ <!--<translate>-->
208
+ <!--<modules>-->
209
+ <!--<translations>-->
210
+ <!--<files>-->
211
+ <!--<default>Pb_Pbgsp.csv</default>-->
212
+ <!--</files>-->
213
+ <!--</translations>-->
214
+ <!--</modules>-->
215
+ <!--</translate>-->
216
+ <!--</frontend>-->
217
+
218
+ <default>
219
+ <carriers>
220
+ <pbgsp>
221
+ <active>1</active>
222
+ <sallowspecific>0</sallowspecific>
223
+ <model>Pb_Pbgsp_Model_Carrier_ShippingMethod</model>
224
+ <specificerrmsg>
225
+ This shipping method is currently unavailable.
226
+ If you would like to ship using this shipping
227
+ method, please contact us.
228
+ </specificerrmsg>
229
+ <handling_type>F</handling_type>
230
+ <catalog_diff>1</catalog_diff>
231
+ <catalog_full>1</catalog_full>
232
+ <catalog_size>10000</catalog_size>
233
+ <catalog_encryption_enabled>0</catalog_encryption_enabled>
234
+ <asn_generation_enabled>1</asn_generation_enabled>
235
+ <suppress_domestic_tracking>1</suppress_domestic_tracking>
236
+ <custom_shipment_email_subject><![CDATA[{{var store.getFrontendName()}}: Shipment confirmation for Order # {{var order.increment_id}}]]>
237
+ </custom_shipment_email_subject>
238
+ <custom_shipment_email_template><![CDATA[<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Hello, {{htmlescape var=$order.getCustomerName()}}</h1>
239
+ <p style="font-size:12px; line-height:16px; margin:0;">
240
+ Thank you for your order from {{var store.getFrontendName()}}.
241
+ You can check the status of your order by <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">logging into your account</a>.
242
+
243
+ </p>
244
+ <p style="font-size:12px; line-height:16px; margin:0;">
245
+ Your shipping confirmation is below. Thank you again for your business.
246
+ </p>
247
+
248
+ <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} has been shipped from local warehouse to international shipment hub from where it will be shipped to your country.</h2>
249
+
250
+ ]]>
251
+ </custom_shipment_email_template>
252
+ <separate_log_file>0</separate_log_file>
253
+
254
+ <shipping_services>
255
+ <POSTAL_PRIORITY>
256
+ <title>Standard</title>
257
+ <enabled>0</enabled>
258
+ </POSTAL_PRIORITY>
259
+ <FEDEX_ECONOMY>
260
+ <title>Express</title>
261
+ <enabled>1</enabled>
262
+ </FEDEX_ECONOMY>
263
+ <FEDEX_PRIORITY>
264
+ <title>Express Plus</title>
265
+ <enabled>1</enabled>
266
+ </FEDEX_PRIORITY>
267
+ <AE_STANDARD>
268
+ <title>Premier</title>
269
+ <enabled>1</enabled>
270
+ </AE_STANDARD>
271
+ <AU_STANDARD>
272
+ <title>Premier</title>
273
+ <enabled>1</enabled>
274
+ </AU_STANDARD>
275
+ <CN_STANDARD>
276
+ <title>Premier</title>
277
+ <enabled>1</enabled>
278
+ </CN_STANDARD>
279
+ <CPC_EXPRESS>
280
+ <title>Premier Plus</title>
281
+ <enabled>1</enabled>
282
+ </CPC_EXPRESS>
283
+ <CPC_STANDARD>
284
+ <title>Premier</title>
285
+ <enabled>1</enabled>
286
+ </CPC_STANDARD>
287
+ <EU_STANDARD>
288
+ <title>Premier</title>
289
+ <enabled>1</enabled>
290
+ </EU_STANDARD>
291
+ <HK_STANDARD>
292
+ <title>Premier</title>
293
+ <enabled>1</enabled>
294
+ </HK_STANDARD>
295
+ <KR_STANDARD>
296
+ <title>Premier</title>
297
+ <enabled>1</enabled>
298
+ </KR_STANDARD>
299
+ <NZ_STANDARD>
300
+ <title>Premier</title>
301
+ <enabled>1</enabled>
302
+ </NZ_STANDARD>
303
+ <PH_STANDARD>
304
+ <title>Premier</title>
305
+ <enabled>1</enabled>
306
+ </PH_STANDARD>
307
+ <SG_STANDARD>
308
+ <title>Premier</title>
309
+ <enabled>1</enabled>
310
+ </SG_STANDARD>
311
+ <TH_STANDARD>
312
+ <title>Premier</title>
313
+ <enabled>1</enabled>
314
+ </TH_STANDARD>
315
+ <TW_STANDARD>
316
+ <title>Premier</title>
317
+ <enabled>1</enabled>
318
+ </TW_STANDARD>
319
+ </shipping_services>
320
+ <error_messages>
321
+ <_1005001>
322
+ <display>The shipping address is invalid.</display>
323
+ </_1005001>
324
+ <_1005002>
325
+ <display>The consignee information is invalid.</display>
326
+ </_1005002>
327
+ <_1005003>
328
+ <display>The COP transportation information is invalid.</display>
329
+ </_1005003>
330
+ <_1005004>
331
+ <display>The requested return currency is invalid.</display>
332
+ </_1005004>
333
+ <_1005005>
334
+ <display>The request currency is not supported for the target country.</display>
335
+ </_1005005>
336
+ <_1005006>
337
+ <display>The order cannot be shipped by the method selected.</display>
338
+ </_1005006>
339
+ <_1005007>
340
+ <display>The order value has exceeded the allowed value.</display>
341
+ </_1005007>
342
+ <_1005008>
343
+ <display>Invalid fields in parcels.</display>
344
+ </_1005008>
345
+ <_1005009>
346
+ <display>Invalid fields in commoditySources.</display>
347
+ </_1005009>
348
+ <_1005010>
349
+ <display>This basket is over the dollar value for international shipping. Please remove some items before proceeding.</display>
350
+ </_1005010>
351
+ <_1005011>
352
+ <display>There are errors at the Quote Item Level.</display>
353
+ </_1005011>
354
+ <_1005012>
355
+ <display>The order exceeded the weight limit.</display>
356
+ </_1005012>
357
+ <_1005013>
358
+ <display>The shipping address has missing fields.</display>
359
+ </_1005013>
360
+ <_1005014>
361
+ <display>Missing fields in basket.</display>
362
+ </_1005014>
363
+ <_1005015>
364
+ <display>Invalid fields in basket.</display>
365
+ </_1005015>
366
+ <_1005016>
367
+ <display>The consignee information is missing.</display>
368
+ </_1005016>
369
+ <_1005017>
370
+ <display>The COP transportation information is missing.</display>
371
+ </_1005017>
372
+ <_1005018>
373
+ <display>Shipping Speed unavailable.</display>
374
+ </_1005018>
375
+ <_1005018>
376
+ <display>Shipping Speed unavailable.</display>
377
+ </_1005018>
378
+ <_1005019>
379
+ <display>Missing Basket.</display>
380
+ </_1005019>
381
+ <_1005020>
382
+ <display>Missing Parcel Fields.</display>
383
+ </_1005020>
384
+ <_1005021>
385
+ <display>Missing fields in the basket commodity source.</display>
386
+ </_1005021>
387
+ <_1005022>
388
+ <display>Invalid Parcel Fields.</display>
389
+ </_1005022>
390
+ <_1006001>
391
+ <display>The commodity was invalid.</display>
392
+ </_1006001>
393
+ <_1006002>
394
+ <display>The commodity is too large to ship (length, width or height).</display>
395
+ </_1006002>
396
+ <_1006003>
397
+ <display>The commodity cannot be shipped to the COD.</display>
398
+ </_1006003>
399
+ <_1006004>
400
+ <display>The commodity has a negative price.</display>
401
+ </_1006004>
402
+ <_1006005>
403
+ <display>The commodity’s price was too low and did not have a dutiable value.</display>
404
+ </_1006005>
405
+ <_1006006>
406
+ <display>The item price exceeds maximum.</display>
407
+ </_1006006>
408
+ <_1006007>
409
+ <display>Item weight exceeds maximum.</display>
410
+ </_1006007>
411
+ <_1006008>
412
+ <display>Invalid commodity rated data. Commodity cannot be shipped at this time. This is an internal error and should be raised to PB immediately. .</display>
413
+ </_1006008>
414
+ <_1006009>
415
+ <display>The Commodity is restricted for this Country of Destination.</display>
416
+ </_1006009>
417
+ <_10060010>
418
+ <display>Commodity cannot be quoted.</display>
419
+ </_10060010>
420
+ <_10060011>
421
+ <display>Commodity cannot shipped to the address specified.</display>
422
+ </_10060011>
423
+ <_1007001>
424
+ <display>Order value exceeded on this line.</display>
425
+ </_1007001>
426
+ <_1007002>
427
+ <display>Line too large to ship (length, width or height of the shipping box).</display>
428
+ </_1007002>
429
+ <_1007003>
430
+ <display>The quantity is invalid or missing.</display>
431
+ </_1007003>
432
+ <_1007004>
433
+ <display>Weight Value exceeded on this line.</display>
434
+ </_1007004>
435
+ <_1007005>
436
+ <display>Errors in the kitContents.</display>
437
+ </_1007005>
438
+ <_1007006>
439
+ <display>Missing fields in basket line.</display>
440
+ </_1007006>
441
+ <_1007007>
442
+ <display>Invalid fields in basket line.</display>
443
+ </_1007007>
444
+ <_1007008>
445
+ <display>Quantity exceeded for Country of Destination.</display>
446
+ </_1007008>
447
+ </error_messages>
448
+ </pbgsp>
449
+ </carriers>
450
+ </default>
451
+
452
+ <!-- Please modify this part for CRON JOB
453
+ For more information on Magento Cron Job, please visit the following url:
454
+ http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#built-in_cron_jobs
455
+ -->
456
+ <crontab>
457
+ <jobs>
458
+ <pb_pbgsp>
459
+ <schedule>
460
+ <cron_expr>30 * * * *</cron_expr>
461
+ </schedule>
462
+ <run>
463
+ <model>pb_pbgsp/catalog_cron::catalogSync</model>
464
+ </run>
465
+ </pb_pbgsp>
466
+ <pb_notifications>
467
+ <schedule>
468
+ <cron_expr>20 * * * *</cron_expr>
469
+ </schedule>
470
+ <run>
471
+ <model>pb_pbgsp/catalog_cron::processStatusNotifications</model>
472
+ </run>
473
+ </pb_notifications>
474
+ </jobs>
475
+ </crontab>
476
+ <adminhtml>
477
+ <events>
478
+ <!--<sales_order_save_commit_after>-->
479
+ <!--<observers>-->
480
+ <!--<Pb_Pbgsp_CreateParcel>-->
481
+ <!--<type>model</type>-->
482
+ <!--<class>pb_pbgsp/observer</class>-->
483
+ <!--<method>generateInboundParcelPreAdvice</method>-->
484
+ <!--</Pb_Pbgsp_CreateParcel>-->
485
+ <!--</observers>-->
486
+ <!--</sales_order_save_commit_after>-->
487
+ <sales_order_shipment_save_after>
488
+ <observers>
489
+ <Pb_Pbgsp_CreateParcel>
490
+ <type>model</type>
491
+ <class>pb_pbgsp/observer</class>
492
+ <method>generateInboundParcelPreAdvice</method>
493
+ </Pb_Pbgsp_CreateParcel>
494
+ </observers>
495
+ </sales_order_shipment_save_after>
496
+ </events>
497
+ <!--<translate>-->
498
+ <!--<modules>-->
499
+ <!--<translations>-->
500
+ <!--<files>-->
501
+ <!--<default>Pb_Pbgsp.csv</default>-->
502
+ <!--</files>-->
503
+ <!--</translations>-->
504
+ <!--</modules>-->
505
+ <!--</translate>-->
506
+ </adminhtml>
507
+
508
+ </config>
509
+
app/code/local/Pb/Pbgsp/etc/system.xml CHANGED
@@ -1,361 +1,379 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <sections>
4
- <carriers>
5
- <groups>
6
- <pbgsp translate="label" module="shipping">
7
- <label>Pitney Bowes PBGSP</label>
8
- <frontend_type>text</frontend_type>
9
- <sort_order>13</sort_order>
10
- <show_in_default>1</show_in_default>
11
- <show_in_website>1</show_in_website>
12
- <show_in_store>1</show_in_store>
13
- <fields>
14
- <active translate="label">
15
- <label>Enabled</label>
16
- <frontend_type>select</frontend_type>
17
- <source_model>adminhtml/system_config_source_yesno</source_model>
18
- <sort_order>1</sort_order>
19
- <show_in_default>1</show_in_default>
20
- <show_in_website>1</show_in_website>
21
- <show_in_store>1</show_in_store>
22
- </active>
23
- <merchantcode translate="label">
24
- <label>Merchant Code</label>
25
- <frontend_type>text</frontend_type>
26
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
27
- <sort_order>10</sort_order>
28
- <show_in_default>1</show_in_default>
29
- <show_in_website>1</show_in_website>
30
- <show_in_store>1</show_in_store>
31
- </merchantcode>
32
- <apiurl translate="label">
33
- <label>API Endpoint</label>
34
- <frontend_type>text</frontend_type>
35
- <sort_order>18</sort_order>
36
- <show_in_default>1</show_in_default>
37
- <show_in_website>1</show_in_website>
38
- <show_in_store>1</show_in_store>
39
- </apiurl>
40
- <order_mgmt_api translate="label">
41
- <label>Order Management API Endpoint</label>
42
- <frontend_type>text</frontend_type>
43
-
44
- <sort_order>19</sort_order>
45
- <show_in_default>1</show_in_default>
46
- <show_in_website>1</show_in_website>
47
- <show_in_store>1</show_in_store>
48
- </order_mgmt_api>
49
- <apiuser translate="label">
50
- <label>API username</label>
51
- <frontend_type>text</frontend_type>
52
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
53
- <sort_order>20</sort_order>
54
- <show_in_default>1</show_in_default>
55
- <show_in_website>1</show_in_website>
56
- <show_in_store>1</show_in_store>
57
- </apiuser>
58
- <apipass translate="label">
59
- <label>API password</label>
60
- <frontend_type>password</frontend_type>
61
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
62
- <sort_order>30</sort_order>
63
- <show_in_default>1</show_in_default>
64
- <show_in_website>1</show_in_website>
65
- <show_in_store>1</show_in_store>
66
- </apipass>
67
- <ftpuser translate="label">
68
- <label>SFTP username</label>
69
- <frontend_type>text</frontend_type>
70
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
71
- <sort_order>40</sort_order>
72
- <show_in_default>1</show_in_default>
73
- <show_in_website>1</show_in_website>
74
- <show_in_store>1</show_in_store>
75
- </ftpuser>
76
- <ftppass translate="label">
77
- <label>SFTP password</label>
78
- <frontend_type>password</frontend_type>
79
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
80
- <sort_order>50</sort_order>
81
- <show_in_default>1</show_in_default>
82
- <show_in_website>1</show_in_website>
83
- <show_in_store>1</show_in_store>
84
- </ftppass>
85
- <ftphost translate="label">
86
- <label>SFTP hostname</label>
87
- <frontend_type>text</frontend_type>
88
- <sort_order>60</sort_order>
89
- <show_in_default>1</show_in_default>
90
- <show_in_website>1</show_in_website>
91
- <show_in_store>1</show_in_store>
92
- </ftphost>
93
- <ftpport translate="label">
94
- <label>SFTP port</label>
95
- <frontend_type>text</frontend_type>
96
- <sort_order>70</sort_order>
97
- <show_in_default>1</show_in_default>
98
- <show_in_website>1</show_in_website>
99
- <show_in_store>1</show_in_store>
100
- </ftpport>
101
- <ftpdir translate="label">
102
- <label>SFTP catalog directory</label>
103
- <frontend_type>text</frontend_type>
104
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
105
- <sort_order>80</sort_order>
106
- <show_in_default>1</show_in_default>
107
- <show_in_website>1</show_in_website>
108
- <show_in_store>1</show_in_store>
109
- </ftpdir>
110
- <catalog_diff translate="label">
111
- <label>Catalog update period (hours, min 1 hour)</label>
112
- <frontend_type>text</frontend_type>
113
- <sort_order>90</sort_order>
114
- <show_in_default>1</show_in_default>
115
- <show_in_website>1</show_in_website>
116
- <show_in_store>1</show_in_store>
117
- </catalog_diff>
118
- <catalog_full translate="label">
119
- <label>Full catalog upload period (days)</label>
120
- <frontend_type>text</frontend_type>
121
- <sort_order>100</sort_order>
122
- <show_in_default>1</show_in_default>
123
- <show_in_website>1</show_in_website>
124
- <show_in_store>1</show_in_store>
125
- </catalog_full>
126
- <catalog_size translate="label">
127
- <label>Maximum Records Per File</label>
128
- <frontend_type>text</frontend_type>
129
- <validate>validate-number</validate>
130
- <sort_order>105</sort_order>
131
- <show_in_default>1</show_in_default>
132
- <show_in_website>1</show_in_website>
133
- <show_in_store>1</show_in_store>
134
- </catalog_size>
135
- <catalog_sender_id translate="label">
136
- <label>Catalog Sender ID</label>
137
- <frontend_type>text</frontend_type>
138
-
139
- <sort_order>106</sort_order>
140
- <show_in_default>1</show_in_default>
141
- <show_in_website>1</show_in_website>
142
- <show_in_store>1</show_in_store>
143
- </catalog_sender_id>
144
- <admin_email translate="label">
145
- <label>Admin Email</label>
146
- <frontend_type>text</frontend_type>
147
- <validate>validate-email</validate>
148
- <sort_order>110</sort_order>
149
- <show_in_default>1</show_in_default>
150
- <show_in_website>1</show_in_website>
151
- <show_in_store>1</show_in_store>
152
- </admin_email>
153
- <catalog_encryption_enabled translate="label">
154
- <label>Catalog Encryption Enabled</label>
155
- <frontend_type>select</frontend_type>
156
- <source_model>adminhtml/system_config_source_yesno</source_model>
157
- <sort_order>115</sort_order>
158
- <show_in_default>1</show_in_default>
159
- <show_in_website>1</show_in_website>
160
- <show_in_store>1</show_in_store>
161
- </catalog_encryption_enabled>
162
- <encryption_public_key translate="label">
163
- <label>Catalog Encryption Public Key</label>
164
- <frontend_type>textarea</frontend_type>
165
- <sort_order>120</sort_order>
166
- <show_in_default>1</show_in_default>
167
- <show_in_website>1</show_in_website>
168
- <show_in_store>1</show_in_store>
169
- </encryption_public_key>
170
- <asn_generation_enabled translate="label">
171
- <label>Generate ASN</label>
172
- <frontend_type>select</frontend_type>
173
- <source_model>adminhtml/system_config_source_yesno</source_model>
174
- <sort_order>121</sort_order>
175
- <show_in_default>1</show_in_default>
176
- <show_in_website>1</show_in_website>
177
- <show_in_store>1</show_in_store>
178
- </asn_generation_enabled>
179
-
180
- <!--
181
- If the free_shipping_enable flag enable, the system will check free_shipping_subtotal to give free shipping
182
- otherwise will use shopping cart price rule behaviour
183
- -->
184
- <free_shipping_enable translate="label">
185
- <label>Free shipping with minimum order amount</label>
186
- <frontend_type>select</frontend_type>
187
- <source_model>adminhtml/system_config_source_enabledisable</source_model>
188
- <sort_order>160</sort_order>
189
- <show_in_default>1</show_in_default>
190
- <show_in_website>1</show_in_website>
191
- <show_in_store>1</show_in_store>
192
- </free_shipping_enable>
193
- <free_shipping_subtotal translate="label">
194
- <label>Minimum order amount for free shipping</label>
195
- <frontend_type>text</frontend_type>
196
- <sort_order>170</sort_order>
197
- <show_in_default>1</show_in_default>
198
- <show_in_website>1</show_in_website>
199
- <show_in_store>1</show_in_store>
200
- </free_shipping_subtotal>
201
- <sort_order translate="label">
202
- <label>Sort order</label>
203
- <frontend_type>text</frontend_type>
204
- <sort_order>230</sort_order>
205
- <show_in_default>1</show_in_default>
206
- <show_in_website>1</show_in_website>
207
- <show_in_store>1</show_in_store>
208
- </sort_order>
209
- <title translate="label">
210
- <label>Title</label>
211
- <frontend_type>text</frontend_type>
212
- <sort_order>240</sort_order>
213
- <show_in_default>1</show_in_default>
214
- <show_in_website>1</show_in_website>
215
- <show_in_store>1</show_in_store>
216
- </title>
217
- <!-- added by BigPixel 6/5/2012 -->
218
- <handlingfee translate="label">
219
- <label>Handling Fee</label>
220
- <frontend_type>text</frontend_type>
221
- <sort_order>241</sort_order>
222
- <show_in_default>1</show_in_default>
223
- <show_in_website>1</show_in_website>
224
- <show_in_store>1</show_in_store>
225
- </handlingfee>
226
- <handlingoption translate="label">
227
- <label>Handling Fee Apply As</label>
228
- <frontend_type>select</frontend_type>
229
- <source_model>pb_pbgsp/handlingoptions</source_model>
230
- <sort_order>242</sort_order>
231
- <show_in_default>1</show_in_default>
232
- <show_in_website>1</show_in_website>
233
- <show_in_store>1</show_in_store>
234
- </handlingoption>
235
- <domestic_shipping_fee translate="label">
236
- <label>Domestic Shipping Fee</label>
237
- <frontend_type>text</frontend_type>
238
- <sort_order>243</sort_order>
239
- <show_in_default>1</show_in_default>
240
- <show_in_website>1</show_in_website>
241
- <show_in_store>1</show_in_store>
242
- </domestic_shipping_fee>
243
- <domestic_shipping_option translate="label">
244
- <label>Apply Domestic shipping fee as</label>
245
- <frontend_type>select</frontend_type>
246
- <source_model>pb_pbgsp/handlingoptions</source_model>
247
- <sort_order>244</sort_order>
248
- <show_in_default>1</show_in_default>
249
- <show_in_website>1</show_in_website>
250
- <show_in_store>1</show_in_store>
251
- </domestic_shipping_option>
252
- <delivery_adjustment_min_days translate="label">
253
- <label>Minimum Delivery Days to PB Hub</label>
254
- <frontend_type>text</frontend_type>
255
- <validate>validate-number</validate>
256
- <sort_order>245</sort_order>
257
- <show_in_default>1</show_in_default>
258
- <show_in_website>1</show_in_website>
259
- <show_in_store>1</show_in_store>
260
- </delivery_adjustment_min_days>
261
- <delivery_adjustment_max_days translate="label">
262
- <label>Maximum Delivery Days to PB Hub</label>
263
- <frontend_type>text</frontend_type>
264
- <validate>validate-number</validate>
265
- <sort_order>246</sort_order>
266
- <show_in_default>1</show_in_default>
267
- <show_in_website>1</show_in_website>
268
- <show_in_store>1</show_in_store>
269
- </delivery_adjustment_max_days>
270
- <!-- added by BigPixel 6/5/2012 -->
271
- <sallowspecific translate="label">
272
- <label>Ship to applicable countries</label>
273
- <frontend_type>select</frontend_type>
274
- <sort_order>250</sort_order>
275
- <frontend_class>shipping-applicable-country</frontend_class>
276
- <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
277
- <show_in_default>1</show_in_default>
278
- <show_in_website>1</show_in_website>
279
- <show_in_store>1</show_in_store>
280
- </sallowspecific>
281
- <specificcountry translate="label">
282
- <label>Ship to Specific countries</label>
283
- <frontend_type>multiselect</frontend_type>
284
- <sort_order>251</sort_order>
285
- <source_model>adminhtml/system_config_source_country</source_model>
286
- <show_in_default>1</show_in_default>
287
- <show_in_website>1</show_in_website>
288
- <show_in_store>1</show_in_store>
289
- </specificcountry>
290
- <showmethod translate="label">
291
- <label>Show Method if Not Applicable</label>
292
- <frontend_type>select</frontend_type>
293
- <sort_order>260</sort_order>
294
- <frontend_class>shipping-skip-hide</frontend_class>
295
- <source_model>adminhtml/system_config_source_yesno</source_model>
296
- <show_in_default>1</show_in_default>
297
- <show_in_website>1</show_in_website>
298
- <show_in_store>0</show_in_store>
299
- </showmethod>
300
- <specificerrmsg translate="label">
301
- <label>Displayed Error Message</label>
302
- <frontend_type>textarea</frontend_type>
303
- <sort_order>270</sort_order>
304
- <show_in_default>1</show_in_default>
305
- <show_in_website>1</show_in_website>
306
- <show_in_store>1</show_in_store>
307
- </specificerrmsg>
308
- <!-- test comments -->
309
- <trackinglink translate="label">
310
- <label>Enable Tracking Links</label>
311
- <frontend_type>select</frontend_type>
312
- <source_model>adminhtml/system_config_source_yesno</source_model>
313
- <sort_order>271</sort_order>
314
- <show_in_default>1</show_in_default>
315
- <show_in_website>1</show_in_website>
316
- <show_in_store>1</show_in_store>
317
- </trackinglink>
318
- <suppress_domestic_tracking translate="label">
319
- <label>Suppress Domestic Leg Tracking</label>
320
- <frontend_type>select</frontend_type>
321
- <sort_order>280</sort_order>
322
- <frontend_class>shipping-skip-hide</frontend_class>
323
- <source_model>adminhtml/system_config_source_yesno</source_model>
324
- <show_in_default>1</show_in_default>
325
- <show_in_website>1</show_in_website>
326
- <show_in_store>1</show_in_store>
327
- </suppress_domestic_tracking>
328
- <custom_shipment_email_subject translate="label">
329
- <label>Custom Shipment Email Subject</label>
330
- <frontend_type>text</frontend_type>
331
-
332
- <sort_order>281</sort_order>
333
- <show_in_default>1</show_in_default>
334
- <show_in_website>1</show_in_website>
335
- <show_in_store>1</show_in_store>
336
- </custom_shipment_email_subject>
337
- <custom_shipment_email_template>
338
- <label>Custom Shipment Email</label>
339
- <frontend_type>textarea</frontend_type>
340
- <sort_order>282</sort_order>
341
- <show_in_default>1</show_in_default>
342
- <show_in_website>1</show_in_website>
343
- <show_in_store>1</show_in_store>
344
- </custom_shipment_email_template>
345
- <separate_log_file translate="label">
346
- <label>Log in separate file</label>
347
- <frontend_type>select</frontend_type>
348
- <sort_order>283</sort_order>
349
- <frontend_class>shipping-skip-hide</frontend_class>
350
- <source_model>adminhtml/system_config_source_yesno</source_model>
351
- <show_in_default>1</show_in_default>
352
- <show_in_website>1</show_in_website>
353
- <show_in_store>1</show_in_store>
354
- </separate_log_file>
355
- </fields>
356
- </pbgsp>
357
- </groups>
358
- </carriers>
359
-
360
- </sections>
361
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <carriers>
5
+ <groups>
6
+ <pbgsp translate="label" module="shipping">
7
+ <label>Pitney Bowes PBGSP</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>13</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </active>
23
+ <merchantcode translate="label">
24
+ <label>Merchant Code</label>
25
+ <frontend_type>text</frontend_type>
26
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
27
+ <sort_order>10</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ </merchantcode>
32
+ <authorization_endpoint translate="label">
33
+ <label>Authorization Endpoint</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>15</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </authorization_endpoint>
40
+ <checkout_endpoint translate="label">
41
+ <label>Checkout Endpoint</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>16</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </checkout_endpoint>
48
+ <order_mgmt_api translate="label">
49
+ <label>ASN Endpoint</label>
50
+ <frontend_type>text</frontend_type>
51
+
52
+ <sort_order>17</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </order_mgmt_api>
57
+ <apiuser translate="label">
58
+ <label>API username</label>
59
+ <frontend_type>text</frontend_type>
60
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
61
+ <sort_order>20</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ </apiuser>
66
+ <apipass translate="label">
67
+ <label>API password</label>
68
+ <frontend_type>password</frontend_type>
69
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
70
+ <sort_order>30</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </apipass>
75
+ <ftpuser translate="label">
76
+ <label>SFTP username</label>
77
+ <frontend_type>text</frontend_type>
78
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
79
+ <sort_order>40</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ </ftpuser>
84
+ <ftppass translate="label">
85
+ <label>SFTP password</label>
86
+ <frontend_type>password</frontend_type>
87
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
88
+ <sort_order>50</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </ftppass>
93
+ <ftphost translate="label">
94
+ <label>SFTP hostname</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>60</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ </ftphost>
101
+ <ftpport translate="label">
102
+ <label>SFTP port</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>70</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ </ftpport>
109
+ <ftpdir translate="label">
110
+ <label>SFTP catalog directory</label>
111
+ <frontend_type>text</frontend_type>
112
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
113
+ <sort_order>80</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>1</show_in_store>
117
+ </ftpdir>
118
+ <catalog_diff translate="label">
119
+ <label>Catalog update period (hours, min 1 hour)</label>
120
+ <frontend_type>text</frontend_type>
121
+ <sort_order>90</sort_order>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ </catalog_diff>
126
+ <catalog_full translate="label">
127
+ <label>Full catalog upload period (days)</label>
128
+ <frontend_type>text</frontend_type>
129
+ <sort_order>100</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>1</show_in_website>
132
+ <show_in_store>1</show_in_store>
133
+ </catalog_full>
134
+ <catalog_size translate="label">
135
+ <label>Maximum Records Per File</label>
136
+ <frontend_type>text</frontend_type>
137
+ <validate>validate-number</validate>
138
+ <sort_order>105</sort_order>
139
+ <show_in_default>1</show_in_default>
140
+ <show_in_website>1</show_in_website>
141
+ <show_in_store>1</show_in_store>
142
+ </catalog_size>
143
+ <catalog_sender_id translate="label">
144
+ <label>Catalog Sender ID</label>
145
+ <frontend_type>text</frontend_type>
146
+
147
+ <sort_order>106</sort_order>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ </catalog_sender_id>
152
+ <admin_email translate="label">
153
+ <label>Admin Email</label>
154
+ <frontend_type>text</frontend_type>
155
+ <validate>validate-email</validate>
156
+ <sort_order>110</sort_order>
157
+ <show_in_default>1</show_in_default>
158
+ <show_in_website>1</show_in_website>
159
+ <show_in_store>1</show_in_store>
160
+ </admin_email>
161
+ <catalog_encryption_enabled translate="label">
162
+ <label>Catalog Encryption Enabled</label>
163
+ <frontend_type>select</frontend_type>
164
+ <source_model>adminhtml/system_config_source_yesno</source_model>
165
+ <sort_order>115</sort_order>
166
+ <show_in_default>1</show_in_default>
167
+ <show_in_website>1</show_in_website>
168
+ <show_in_store>1</show_in_store>
169
+ </catalog_encryption_enabled>
170
+ <encryption_public_key translate="label">
171
+ <label>Catalog Encryption Public Key</label>
172
+ <frontend_type>textarea</frontend_type>
173
+ <sort_order>120</sort_order>
174
+ <show_in_default>1</show_in_default>
175
+ <show_in_website>1</show_in_website>
176
+ <show_in_store>1</show_in_store>
177
+ </encryption_public_key>
178
+ <asn_generation_enabled translate="label">
179
+ <label>Generate ASN</label>
180
+ <frontend_type>select</frontend_type>
181
+ <source_model>adminhtml/system_config_source_yesno</source_model>
182
+ <sort_order>121</sort_order>
183
+ <show_in_default>1</show_in_default>
184
+ <show_in_website>1</show_in_website>
185
+ <show_in_store>1</show_in_store>
186
+ </asn_generation_enabled>
187
+
188
+ <!--
189
+ If the free_shipping_enable flag enable, the system will check free_shipping_subtotal to give free shipping
190
+ otherwise will use shopping cart price rule behaviour
191
+ -->
192
+ <free_shipping_enable translate="label">
193
+ <label>Free shipping with minimum order amount</label>
194
+ <frontend_type>select</frontend_type>
195
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
196
+ <sort_order>160</sort_order>
197
+ <show_in_default>1</show_in_default>
198
+ <show_in_website>1</show_in_website>
199
+ <show_in_store>1</show_in_store>
200
+ </free_shipping_enable>
201
+ <free_shipping_subtotal translate="label">
202
+ <label>Minimum order amount for free shipping</label>
203
+ <frontend_type>text</frontend_type>
204
+ <sort_order>170</sort_order>
205
+ <show_in_default>1</show_in_default>
206
+ <show_in_website>1</show_in_website>
207
+ <show_in_store>1</show_in_store>
208
+ </free_shipping_subtotal>
209
+ <free_tax_enable translate="label">
210
+ <label>Enable zero tax for customer</label>
211
+ <frontend_type>select</frontend_type>
212
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
213
+ <sort_order>175</sort_order>
214
+ <show_in_default>1</show_in_default>
215
+ <show_in_website>1</show_in_website>
216
+ <show_in_store>1</show_in_store>
217
+ </free_tax_enable>
218
+
219
+ <sort_order translate="label">
220
+ <label>Sort order</label>
221
+ <frontend_type>text</frontend_type>
222
+ <sort_order>230</sort_order>
223
+ <show_in_default>1</show_in_default>
224
+ <show_in_website>1</show_in_website>
225
+ <show_in_store>1</show_in_store>
226
+ </sort_order>
227
+ <title translate="label">
228
+ <label>Title</label>
229
+ <frontend_type>text</frontend_type>
230
+ <sort_order>240</sort_order>
231
+ <show_in_default>1</show_in_default>
232
+ <show_in_website>1</show_in_website>
233
+ <show_in_store>1</show_in_store>
234
+ </title>
235
+ <!-- added by BigPixel 6/5/2012 -->
236
+ <handlingfee translate="label">
237
+ <label>Handling Fee</label>
238
+ <frontend_type>text</frontend_type>
239
+ <sort_order>241</sort_order>
240
+ <show_in_default>1</show_in_default>
241
+ <show_in_website>1</show_in_website>
242
+ <show_in_store>1</show_in_store>
243
+ </handlingfee>
244
+ <handlingoption translate="label">
245
+ <label>Handling Fee Apply As</label>
246
+ <frontend_type>select</frontend_type>
247
+ <source_model>pb_pbgsp/handlingoptions</source_model>
248
+ <sort_order>242</sort_order>
249
+ <show_in_default>1</show_in_default>
250
+ <show_in_website>1</show_in_website>
251
+ <show_in_store>1</show_in_store>
252
+ </handlingoption>
253
+ <domestic_shipping_fee translate="label">
254
+ <label>Domestic Shipping Fee</label>
255
+ <frontend_type>text</frontend_type>
256
+ <sort_order>243</sort_order>
257
+ <show_in_default>1</show_in_default>
258
+ <show_in_website>1</show_in_website>
259
+ <show_in_store>1</show_in_store>
260
+ </domestic_shipping_fee>
261
+ <domestic_shipping_option translate="label">
262
+ <label>Apply Domestic shipping fee as</label>
263
+ <frontend_type>select</frontend_type>
264
+ <source_model>pb_pbgsp/handlingoptions</source_model>
265
+ <sort_order>244</sort_order>
266
+ <show_in_default>1</show_in_default>
267
+ <show_in_website>1</show_in_website>
268
+ <show_in_store>1</show_in_store>
269
+ </domestic_shipping_option>
270
+ <delivery_adjustment_min_days translate="label">
271
+ <label>Minimum Delivery Days to PB Hub</label>
272
+ <frontend_type>text</frontend_type>
273
+ <validate>validate-number</validate>
274
+ <sort_order>245</sort_order>
275
+ <show_in_default>1</show_in_default>
276
+ <show_in_website>1</show_in_website>
277
+ <show_in_store>1</show_in_store>
278
+ </delivery_adjustment_min_days>
279
+ <delivery_adjustment_max_days translate="label">
280
+ <label>Maximum Delivery Days to PB Hub</label>
281
+ <frontend_type>text</frontend_type>
282
+ <validate>validate-number</validate>
283
+ <sort_order>246</sort_order>
284
+ <show_in_default>1</show_in_default>
285
+ <show_in_website>1</show_in_website>
286
+ <show_in_store>1</show_in_store>
287
+ </delivery_adjustment_max_days>
288
+ <!-- added by BigPixel 6/5/2012 -->
289
+ <sallowspecific translate="label">
290
+ <label>Ship to applicable countries</label>
291
+ <frontend_type>select</frontend_type>
292
+ <sort_order>250</sort_order>
293
+ <frontend_class>shipping-applicable-country</frontend_class>
294
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
295
+ <show_in_default>1</show_in_default>
296
+ <show_in_website>1</show_in_website>
297
+ <show_in_store>1</show_in_store>
298
+ </sallowspecific>
299
+ <specificcountry translate="label">
300
+ <label>Ship to Specific countries</label>
301
+ <frontend_type>multiselect</frontend_type>
302
+ <sort_order>251</sort_order>
303
+ <source_model>adminhtml/system_config_source_country</source_model>
304
+ <show_in_default>1</show_in_default>
305
+ <show_in_website>1</show_in_website>
306
+ <show_in_store>1</show_in_store>
307
+ </specificcountry>
308
+ <showmethod translate="label">
309
+ <label>Show Method if Not Applicable</label>
310
+ <frontend_type>select</frontend_type>
311
+ <sort_order>260</sort_order>
312
+ <frontend_class>shipping-skip-hide</frontend_class>
313
+ <source_model>adminhtml/system_config_source_yesno</source_model>
314
+ <show_in_default>1</show_in_default>
315
+ <show_in_website>1</show_in_website>
316
+ <show_in_store>0</show_in_store>
317
+ </showmethod>
318
+ <specificerrmsg translate="label">
319
+ <label>Displayed Error Message</label>
320
+ <frontend_type>textarea</frontend_type>
321
+ <sort_order>270</sort_order>
322
+ <show_in_default>1</show_in_default>
323
+ <show_in_website>1</show_in_website>
324
+ <show_in_store>1</show_in_store>
325
+ </specificerrmsg>
326
+ <!-- test comments -->
327
+ <trackinglink translate="label">
328
+ <label>Enable Tracking Links</label>
329
+ <frontend_type>select</frontend_type>
330
+ <source_model>adminhtml/system_config_source_yesno</source_model>
331
+ <sort_order>271</sort_order>
332
+ <show_in_default>1</show_in_default>
333
+ <show_in_website>1</show_in_website>
334
+ <show_in_store>1</show_in_store>
335
+ </trackinglink>
336
+ <suppress_domestic_tracking translate="label">
337
+ <label>Suppress Domestic Leg Tracking</label>
338
+ <frontend_type>select</frontend_type>
339
+ <sort_order>280</sort_order>
340
+ <frontend_class>shipping-skip-hide</frontend_class>
341
+ <source_model>adminhtml/system_config_source_yesno</source_model>
342
+ <show_in_default>1</show_in_default>
343
+ <show_in_website>1</show_in_website>
344
+ <show_in_store>1</show_in_store>
345
+ </suppress_domestic_tracking>
346
+ <custom_shipment_email_subject translate="label">
347
+ <label>Custom Shipment Email Subject</label>
348
+ <frontend_type>text</frontend_type>
349
+
350
+ <sort_order>281</sort_order>
351
+ <show_in_default>1</show_in_default>
352
+ <show_in_website>1</show_in_website>
353
+ <show_in_store>1</show_in_store>
354
+ </custom_shipment_email_subject>
355
+ <custom_shipment_email_template>
356
+ <label>Custom Shipment Email</label>
357
+ <frontend_type>textarea</frontend_type>
358
+ <sort_order>282</sort_order>
359
+ <show_in_default>1</show_in_default>
360
+ <show_in_website>1</show_in_website>
361
+ <show_in_store>1</show_in_store>
362
+ </custom_shipment_email_template>
363
+ <separate_log_file translate="label">
364
+ <label>Log in separate file</label>
365
+ <frontend_type>select</frontend_type>
366
+ <sort_order>283</sort_order>
367
+ <frontend_class>shipping-skip-hide</frontend_class>
368
+ <source_model>adminhtml/system_config_source_yesno</source_model>
369
+ <show_in_default>1</show_in_default>
370
+ <show_in_website>1</show_in_website>
371
+ <show_in_store>1</show_in_store>
372
+ </separate_log_file>
373
+ </fields>
374
+ </pbgsp>
375
+ </groups>
376
+ </carriers>
377
+
378
+ </sections>
379
+ </config>
app/code/local/Pb/Pbgsp/sql/pbgsp_setup/mysql4-install-1.0.0.php CHANGED
@@ -1,60 +1,96 @@
1
- <?php
2
-
3
-
4
-
5
- $installer = $this;
6
-
7
- $installer->startSetup();
8
-
9
- $installer->run("
10
-
11
- DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/variable')};
12
- CREATE TABLE {$this->getTable('pb_pbgsp/variable')} (
13
- `variable_id` int(11) unsigned NOT NULL auto_increment,
14
- `name` varchar(255) NOT NULL default '',
15
- `value` varchar(255) NOT NULL default '',
16
- PRIMARY KEY (`variable_id`)
17
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
-
19
- DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/ordernumber')};
20
- CREATE TABLE {$this->getTable('pb_pbgsp/ordernumber')} (
21
- `ordernumber_id` int(11) unsigned NOT NULL auto_increment,
22
- `cp_order_number` varchar(255) NOT NULL default '',
23
- `mage_order_number` varchar(255) NOT NULL default '',
24
- `confirmed` tinyint NOT NULL default 0,
25
- `referenced` tinyint NOT NULL default 0,
26
- `hub_id` varchar(50) null,
27
- `hub_street1` varchar(50) null,
28
- `hub_street2` varchar(50) null,
29
- `hub_province_or_state` varchar(50) null,
30
- `hub_country` varchar(50) null,
31
- PRIMARY KEY (`ordernumber_id`)
32
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33
-
34
- DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/inboundparcel')};
35
- CREATE TABLE {$this->getTable('pb_pbgsp/inboundparcel')} (
36
- `inbound_parcel_id` int(11) unsigned NOT NULL auto_increment,
37
- `inbound_parcel` varchar(255) NOT NULL default '',
38
- `mage_order_number` varchar(255) NOT NULL default '',
39
- `pb_order_number` varchar(255) NOT NULL default '',
40
- PRIMARY KEY (`inbound_parcel_id`)
41
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
42
-
43
- ");
44
-
45
- $eav = Mage::getResourceModel('catalog/setup', 'catalog_setup');//new Mage_Eav_Model_Entity_Setup('catalog_setup');
46
- //$eav->removeAttribute('catalog_product','pb_pbgsp_upload');
47
- $eav->addAttribute('catalog_product', 'pb_pbgsp_upload', array(
48
- 'type' => 'int',
49
- 'input' => 'text',
50
- 'label' => 'Last PBGSP upload timestampt',
51
- 'global' => 2,
52
- 'user_defined' => 0,
53
- 'required' => 0,
54
- 'visible' => 1,
55
- 'default' => 0
56
-
57
- ));
58
-
59
- $installer->endSetup();
60
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product: Pb_Pbgsp (1.0.0)
4
+ * Packaged: 2015-06-04T15:09:31+00:00
5
+ * Last Modified: 2015-06-04T15:00:31+00:00
6
+ * File: app/code/local/Pb/Pbgsp/sql/pbgsp_setup/mysql4-install-1.0.0.php
7
+ * Copyright: Copyright (c) 2015 Pitney Bowes <info@pb.com> / All rights reserved.
8
+ */
9
+
10
+
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $installer->run("
16
+
17
+ DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/variable')};
18
+ CREATE TABLE {$this->getTable('pb_pbgsp/variable')} (
19
+ `variable_id` int(11) unsigned NOT NULL auto_increment,
20
+ `name` varchar(255) NOT NULL default '',
21
+ `value` varchar(255) NOT NULL default '',
22
+ PRIMARY KEY (`variable_id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
+
25
+ DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/ordernumber')};
26
+ CREATE TABLE {$this->getTable('pb_pbgsp/ordernumber')} (
27
+ `ordernumber_id` int(11) unsigned NOT NULL auto_increment,
28
+ `cp_order_number` varchar(255) NOT NULL default '',
29
+ `mage_order_number` varchar(255) NOT NULL default '',
30
+ `confirmed` tinyint NOT NULL default 0,
31
+ `referenced` tinyint NOT NULL default 0,
32
+ `hub_id` varchar(50) null,
33
+ `hub_street1` varchar(50) null,
34
+ `hub_street2` varchar(50) null,
35
+ `hub_province_or_state` varchar(50) null,
36
+ `hub_country` varchar(50) null,
37
+ `hub_postal_code` varchar(50) null,
38
+ PRIMARY KEY (`ordernumber_id`)
39
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
40
+
41
+ DROP TABLE IF EXISTS {$this->getTable('pb_pbgsp/inboundparcel')};
42
+ CREATE TABLE {$this->getTable('pb_pbgsp/inboundparcel')} (
43
+ `inbound_parcel_id` int(11) unsigned NOT NULL auto_increment,
44
+ `inbound_parcel` varchar(255) NOT NULL default '',
45
+ `mage_order_number` varchar(255) NOT NULL default '',
46
+ `pb_order_number` varchar(255) NOT NULL default '',
47
+ PRIMARY KEY (`inbound_parcel_id`)
48
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
49
+
50
+ ");
51
+
52
+ $eav = Mage::getResourceModel('catalog/setup', 'catalog_setup');//new Mage_Eav_Model_Entity_Setup('catalog_setup');
53
+ $eav->removeAttribute('catalog_product','pb_pbgsp_upload');
54
+ $eav->addAttribute('catalog_product', 'pb_pbgsp_upload', array(
55
+ 'type' => 'datetime',
56
+ 'input' => 'datetime',
57
+ 'label' => 'Last PBGSP upload timestampt',
58
+ 'global' => 2,
59
+ 'user_defined' => 0,
60
+ 'required' => 0,
61
+ 'visible' => 1,
62
+ 'default' => 0
63
+
64
+ ));
65
+ $eav->removeAttribute('catalog_category','pb_pbgsp_upload');
66
+ $eav->addAttribute('catalog_category', 'pb_pbgsp_upload', array(
67
+ 'type' => 'datetime',
68
+ 'input' => 'datetime',
69
+ 'label' => 'Last PBGSP upload timestampt',
70
+ 'global' => 2,
71
+ 'user_defined' => 0,
72
+ 'required' => 0,
73
+ 'visible' => 1,
74
+ 'default' => 0,
75
+ 'group' => 'PBGSP'
76
+
77
+ ));
78
+
79
+ $eav->removeAttribute('catalog_category','pb_pbgsp_upload_active');
80
+ $eav->addAttribute('catalog_category', 'pb_pbgsp_upload_active', array(
81
+ 'type' => 'int',
82
+ 'input' => 'select',
83
+ 'label' => 'Export to PBGSP',
84
+ 'source' => 'eav/entity_attribute_source_boolean',
85
+ 'global' => 2,
86
+ 'user_defined' => 0,
87
+ 'required' => 0,
88
+ 'visible' => 1,
89
+ 'default' => 1,
90
+ 'group' => 'PBGSP'
91
+
92
+ ));
93
+
94
+
95
+ $installer->endSetup();
96
+ ?>
package.xml CHANGED
@@ -1,8 +1,8 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>pitneybowes_gsp</name>
4
- <version>0.9.0</version>
5
- <stability>beta</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
@@ -24,9 +24,9 @@ To learn more, go to &lt;a href="http://www.pb.com/ecom"&gt;http://www.pb.com/ec
24
  </description>
25
  <notes>Initial Stable GSP release for Magento Connect.</notes>
26
  <authors><author><name>Raymond Lai</name><user>r3lai</user><email>raymond.lai@pb.com</email></author></authors>
27
- <date>2015-04-14</date>
28
- <time>11:41:56</time>
29
- <contents><target name="magelocal"><dir name="Pb"><dir name="Pbgsp"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="691656a14608642b25fc9efab2a0c155"/></dir><file name="Totals.php" hash="dbf77cfd835102e99539f062af3b9c55"/></dir></dir></dir><dir name="Checkout"><dir name="Shipping"><dir name="Method"><file name="Available.php" hash="bd20945fe9da40d382898dc013f860ea"/></dir></dir></dir><file name="Form.php" hash="ae0844bdb3c596cb48191a94850423fa"/><dir name="Sales"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="c0d69d334712951c59400ed0911f5ef7"/></dir><file name="Totals.php" hash="ad7708efb7550991df82e4cb8c387270"/></dir></dir></dir><dir name="Model"><file name="Api.php" hash="a0c3d5adbb470590ef4adde3d659addc"/><dir name="Carrier"><file name="ShippingMethod.php" hash="dd79e517a6b17c0e9b7175a6383c5f2d"/></dir><dir name="Catalog"><file name="Category.php" hash="83e2c6c7374d0917eba8fc66d33379c2"/><file name="Cron.php" hash="4c20db78b5e9b0e00f542d922c2a5077"/><file name="File.php" hash="bb9c2f8e88ab97c75cec51eca254219f"/><file name="Product.php" hash="0b9c77ce88c98bb6c4c27f5f0bdbc82e"/></dir><file name="Credentials.php" hash="c8bff1c913d7f0200020af3b04348b1c"/><dir name="Creditmemo"><file name="Duty.php" hash="7aeeaf0203624a0beec9c87c4176b120"/></dir><file name="Handlingoptions.php" hash="1e8b845d2a595e54bab55dc44e55a1be"/><file name="Helper.php" hash="b68156a8556a00a379ef121ece805d06"/><file name="Inboundparcel.php" hash="3b149c32bf1c49eb255c16811806327f"/><dir name="Invoice"><file name="Duty.php" hash="783ece295715095c41041d7bd636d989"/></dir><file name="Messages.php" hash="073a95d2033acadf0e66156b25e073f6"/><dir name="Mysql4"><dir name="Inboundparcel"><file name="Collection.php" hash="9e22c4602437006a588288c7bb4ebe00"/></dir><file name="Inboundparcel.php" hash="1375e23587f63783e2c28328bfa6a7e4"/><dir name="Ordernumber"><file name="Collection.php" hash="952c035d9a62093a5f57b2e1b94315c6"/></dir><file name="Ordernumber.php" hash="a798162bba3d6385fde9a617913d05c1"/><dir name="Variable"><file name="Collection.php" hash="758c590a398acca4a5825bbd49de18fe"/></dir><file name="Variable.php" hash="bedf862cc7934157b892c9dd8efc5b86"/></dir><file name="Observer.php" hash="71449974b3b49766405faa0a1ca3fb0b"/><file name="Ordernumber.php" hash="79180b9acee40a15d02238d303ef2b78"/><dir name="Pdf"><file name="Tax.php" hash="0e787b3f319d4c13c2c929288f38b8f9"/></dir><dir name="Quote"><file name="Duty.php" hash="931e21fae6443d99a094b3ee409eae25"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="af6d513cce9b9f59eab82cec0f2156a1"/></dir></dir><dir name="Sales"><dir name="Order"><file name="Shipment.php" hash="8caca8e1a7fc7437b6c865656b88ecf8"/></dir></dir><file name="Util.php" hash="86bf7854c9466e98464aac409e6e3604"/><file name="Variable.php" hash="384e9eb6d24b92596bc259fbc6a55756"/></dir><file name="README" hash="5baea7c4c231d8cda23465a1abd5427e"/><dir name="etc"><file name="config.xml" hash="6af31f94bb2b26b9cd87cb7c0da86ac3"/><file name="system.xml" hash="e34d51c16e5068d4f76ceff5b00781e1"/></dir><dir name="sql"><dir name="pbgsp_setup"><file name="mysql4-install-1.0.0.php" hash="0c22ce6149ffd831eddb9299ffd8eaab"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Pb_Pbgsp.xml" hash="dc3ea1c2b33fc8e526486c17a24965a4"/></dir></target></contents>
30
  <compatible/>
31
  <dependencies><required><php><min>5.1.0</min><max>5.3.3</max></php><extension><name>gnupg</name><min>1.3.5</min><max>1.3.6</max></extension></required></dependencies>
32
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>pitneybowes_gsp</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
24
  </description>
25
  <notes>Initial Stable GSP release for Magento Connect.</notes>
26
  <authors><author><name>Raymond Lai</name><user>r3lai</user><email>raymond.lai@pb.com</email></author></authors>
27
+ <date>2015-06-04</date>
28
+ <time>14:15:41</time>
29
+ <contents><target name="magelocal"><dir name="Pb"><dir name="Pbgsp"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="4d860488518cd57f776c3d2fe423437a"/></dir><file name="Totals.php" hash="cf0e69cb9d436ccf2aafb99bd0fc272c"/></dir></dir></dir><dir name="Checkout"><dir name="Shipping"><dir name="Method"><file name="Available.php" hash="a8ba337dd2cb0281f95f548a8f69c47a"/></dir></dir></dir><file name="Form.php" hash="82c8f0e9b90991f393d7e04919f8d2f8"/><dir name="Sales"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="f2b39fe7a2a19e96edd934c05bac50b1"/></dir><file name="Totals.php" hash="d9dfa66b18a79d1ef5e31607de445207"/></dir></dir></dir><dir name="Model"><file name="Api.php" hash="fa5ee4bb423ddf60c097fb61d12bc43b"/><dir name="Carrier"><file name="ShippingMethod.php" hash="06b0c62606456ec1b9dcd4ea413e6bc4"/></dir><dir name="Catalog"><file name="Category.php" hash="002f69dea2c831e04399600c15885964"/><file name="Cron.php" hash="f6992f831ee453b15a95cffed9332a1f"/><file name="File.php" hash="779960aa2d2ab50382127890c7a0ad87"/><file name="Product.php" hash="d09b2f56cb76a693ef87a8452834e96e"/></dir><file name="Credentials.php" hash="946390c588ec28db30343250e23f988b"/><dir name="Creditmemo"><file name="Duty.php" hash="b123de9cdcaac1de04cdcf94d4d1fc06"/></dir><file name="Handlingoptions.php" hash="36aeb268f7ecb615854039b9981ccf9f"/><file name="Helper.php" hash="18781bf68a57a8c416c1a37f041ac412"/><file name="Inboundparcel.php" hash="8ead6048c8ecb66327e2b83d2af3dcc4"/><dir name="Invoice"><file name="Duty.php" hash="1d531b8c6de4345481caff2cd916f836"/></dir><file name="Messages.php" hash="728b54383aafa7f4e6a7e57202bb813f"/><dir name="Mysql4"><dir name="Inboundparcel"><file name="Collection.php" hash="e1c99046f446067d67b9163151644886"/></dir><file name="Inboundparcel.php" hash="fd0e3e6f43740107583e1ad20c384aea"/><dir name="Ordernumber"><file name="Collection.php" hash="a57c9def45246f684886a89222ff7130"/></dir><file name="Ordernumber.php" hash="bf03953bfcc552fafc142ade3c02fc47"/><dir name="Variable"><file name="Collection.php" hash="230ed58bde61c41735ae9641b5309d2c"/></dir><file name="Variable.php" hash="978acaba585304135920a747e0dbeaaf"/></dir><file name="Observer.php" hash="9ef19992c6015cb6e187802a9307b572"/><file name="Ordernumber.php" hash="14709487c0af7b66f281a50cc9d1b7db"/><dir name="Pdf"><file name="Tax.php" hash="707cc6e01dfd325229c5831ce4cfc4e5"/></dir><dir name="Quote"><file name="Duty.php" hash="8d6d1951ef8e5782c7fa524ea8100764"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="4da3fcbfbbaef186a630cd0d83309af5"/></dir></dir><dir name="Sales"><dir name="Order"><file name="Shipment.php" hash="0d65ba103b988bdade20f087a50cefc9"/></dir></dir><file name="Util.php" hash="7b417bc17989eb5ac8cf6d2de0af9f4f"/><file name="Variable.php" hash="16eea17bd4a8f87d06b879c2ce5f8248"/></dir><file name="README" hash="5baea7c4c231d8cda23465a1abd5427e"/><dir name="data"><dir name="pb_pbgsp_setup"><file name="data-install-1.0.0.php" hash="157ad9a71ff8a03526729ddae484c9dc"/></dir></dir><dir name="etc"><file name="config.xml" hash="93ae6a04d17083ede60045350c8cdd95"/><file name="system.xml" hash="75bf1ced1440e4dce3f7d1b2f2ec7494"/></dir><dir name="sql"><dir name="pbgsp_setup"><file name="mysql4-install-1.0.0.php" hash="c4cd1f91694e74f08fe512534cfbf20c"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Pb_Pbgsp.xml" hash="dc3ea1c2b33fc8e526486c17a24965a4"/></dir></target></contents>
30
  <compatible/>
31
  <dependencies><required><php><min>5.1.0</min><max>5.3.3</max></php><extension><name>gnupg</name><min>1.3.5</min><max>1.3.6</max></extension></required></dependencies>
32
  </package>