Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. <?php
  2. class BC_CustomModule_Model_Observer
  3. {
  4. public function orderPlaceAfter($observer){
  5. $order = $observer->getOrder();
  6. if(!$order->getShippingDescription()){
  7. switch($order->getShippingMethod()){
  8. case 'goodahead_flatrate_flatrate':
  9. $order->setShippingDescription('Best Way Possible - Flat Rate');
  10. break;
  11. case 'flatrate_flatrate':
  12. $order->setShippingDescription('Pickup - Minneapolis Warehouse Pickup');
  13. break;
  14. case 'matrixrate_matrixrate':
  15. $order->setShippingDescription('SpeeDee Delivery - SpeeDee');
  16. break;
  17. case 'matrixrate_matrixrate_free':
  18. $order->setShippingDescription('SpeeDee Delivery - SpeeDee');
  19. break;
  20. case 'ups_01':
  21. $order->setShippingDescription('UPS - UPS Next Day Air');
  22. break;
  23. case 'ups_02':
  24. $order->setShippingDescription('UPS - UPS Second Day Air');
  25. break;
  26. case 'ups_03':
  27. $order->setShippingDescription('UPS - UPS Ground');
  28. break;
  29. default:
  30. }
  31. $order->save();
  32. }
  33.  
  34. if(!$order->getCustomerEmail()){
  35. $billingAddress = $order->getBillingAddress();
  36. $order->setCustomerId($billingAddress->getCustomerId());
  37. $order->setCustomerEmail($billingAddress->getEmail());
  38. $order->setCustomerFirstname($billingAddress->getFirstname());
  39. $order->setCustomerLastname($billingAddress->getLastname());
  40. $order->save();
  41. }
  42. }
  43.  
  44. public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
  45. {
  46. $shipment = $observer->getEvent()->getShipment();
  47. $order = $shipment->getOrder();
  48. $shippingDesc = $order->getShippingDescription();
  49.  
  50. //Mage::log(print_r($order->getIncrementId(), true), null, 'netsuite-shipment.log', true);
  51. // Mage::log(print_r($order->getStatus(), true), null, 'netsuite-shipment.log', true);
  52. // $shipment = $order->getShipmentsCollection()->getFirstItem();
  53. // $shipmentIncrementId = $shipment->getIncrementId();
  54. // Mage::log(print_r($shipmentIncrementId, true), null, 'netsuite-shipment.log', true);
  55. $_tracks = $shipment->getAllTracks();
  56. foreach ($_tracks as $_track) {
  57. //Mage::log(print_r($_track, true), null, 'netsuite-shipment.log', true);
  58. switch($_track->getTitle()){
  59. case '01':
  60. $order->setShippingDescription('UPS - UPS Ground');
  61. break;
  62. case '02':
  63. $order->setShippingDescription('UPS - UPS Ground');
  64. break;
  65. case '03':
  66. $order->setShippingDescription('UPS - UPS Ground');
  67. break;
  68. case 'matrixrate':
  69. if ($shippingDesc != 'Pickup - Minneapolis Warehouse Pickup')
  70. $order->setShippingDescription('SpeeDee Delivery - SpeeDee');
  71. break;
  72. case 'flatrate':
  73. $order->setShippingDescription('Best Way Possible - Flat Rate');
  74. break;
  75. }
  76. }
  77.  
  78. if($order->getStatus() == 'processing') {
  79. $order->setData('state', 'complete');
  80. $order->setStatus('complete');
  81. $history = $order->addStatusHistoryComment('Order was set to Complete by our automation tool.', false);
  82. $history->setIsCustomerNotified(false);
  83. }
  84.  
  85. $order->save();
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement