1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
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.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class EbayEnterprise_Eb2cGiftwrap_Model_Observers |
17
|
|
|
{ |
18
|
|
|
/** @var EbayEnterprise_Eb2cGiftwrap_Model_Order_Create_Gifting */ |
19
|
|
|
protected $orderGifting; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param array |
23
|
|
|
*/ |
24
|
|
|
public function __construct($args = []) |
25
|
|
|
{ |
26
|
|
|
list( |
27
|
|
|
$this->orderGifting |
28
|
|
|
) = $this->checkTypes( |
29
|
|
|
$this->nullCoalesce($args, 'order_gifting', Mage::getModel('eb2cgiftwrap/order_create_gifting')) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param EbayEnterprise_Eb2cGiftwrap_Model_Order_Create_Gifting |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
protected function checkTypes( |
|
|
|
|
38
|
|
|
EbayEnterprise_Eb2cGiftwrap_Model_Order_Create_Gifting $orderGifting |
|
|
|
|
39
|
|
|
) { |
40
|
|
|
return func_get_args(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array |
45
|
|
|
* @param string|int |
46
|
|
|
* @param mixed |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
|
|
protected function nullCoalesce(array $arr, $key, $default) |
50
|
|
|
{ |
51
|
|
|
return isset($arr[$key]) ? $arr[$key] : $default; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Listen to the 'ebayenterprise_feed_dom_loaded' event |
56
|
|
|
* @see EbayEnterprise_Catalog_Model_Feed_Abstract::processFile |
57
|
|
|
* process a dom document |
58
|
|
|
* @param Varien_Event_Observer $observer |
59
|
|
|
* @return self |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function processDom(Varien_Event_Observer $observer) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
Varien_Profiler::start(__METHOD__); |
64
|
|
|
$event = $observer->getEvent(); |
65
|
|
|
$fileDetail = $event->getFileDetail(); |
66
|
|
|
$importConfig = Mage::getModel('eb2cgiftwrap/feed_import_config'); |
67
|
|
|
$importData = $importConfig->getImportConfigData(); |
68
|
|
|
$feedConfig = $fileDetail['core_feed']->getFeedConfig(); |
69
|
|
|
|
70
|
|
|
// only process the import if the event type is in the allowabled event type configuration for this feed |
71
|
|
|
if (in_array($feedConfig['event_type'], explode(',', $importData['allowable_event_type']))) { |
72
|
|
|
$fileDetail['doc'] = $event->getDoc(); |
73
|
|
|
Mage::getModel('ebayenterprise_catalog/feed_file', $fileDetail)->process( |
74
|
|
|
$importConfig, |
75
|
|
|
Mage::getModel('eb2cgiftwrap/feed_import_items') |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
Varien_Profiler::stop(__METHOD__); |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Add order level gifting to the payload for order create requests. |
84
|
|
|
* |
85
|
|
|
* @param Varien_Event_Observer |
86
|
|
|
*/ |
87
|
|
|
public function handleEbayEnterpriseOrderCreateShipGroup(Varien_Event_Observer $observer) |
88
|
|
|
{ |
89
|
|
|
$event = $observer->getEvent(); |
90
|
|
|
$address = $event->getAddress(); |
91
|
|
|
$order = $event->getOrder(); |
92
|
|
|
|
93
|
|
|
// Gift message id is inconsistent between OPC and multiship checkout. |
94
|
|
|
// In OPC, gift message id will *only* be on the order. In multiship, |
95
|
|
|
// gift message id will *only* be on the address the message applies to. |
96
|
|
|
// This ensures that if the order has a gift message, it gets copied down |
97
|
|
|
// to the primary address. |
98
|
|
|
if ($order->hasGiftMessageId() && $address->isPrimaryShippingAddress()) { |
99
|
|
|
// Technically, this could override a gift message already assigned |
100
|
|
|
// to the address but that should never happen (in Vanilla Magento). |
101
|
|
|
// If the order has a gift message, the address will not (OPC). If the |
102
|
|
|
// address has a gift message, the order will not (multiship checkout). |
103
|
|
|
$address->setGiftMessageId($order->getGiftMessageId()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->orderGifting->injectGifting($address, $event->getShipGroupPayload()); |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Add item level gifting to the payload for order create requests. |
113
|
|
|
* |
114
|
|
|
* @param Varien_Event_Observer |
115
|
|
|
*/ |
116
|
|
|
public function handleEbayEnterpriseOrderCreateItem(Varien_Event_Observer $observer) |
117
|
|
|
{ |
118
|
|
|
$event = $observer->getEvent(); |
119
|
|
|
|
120
|
|
|
$this->orderGifting->injectGifting($event->getItem(), $event->getItemPayload()); |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|