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_Multishipping_Model_Observer |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Ensure shipment amounts have been collected for the order before it |
20
|
|
|
* is saved. |
21
|
|
|
* |
22
|
|
|
* @param Varien_Event_Observer |
23
|
|
|
* @return self |
24
|
|
|
*/ |
25
|
|
|
public function handleSalesOrderSaveBefore(Varien_Event_Observer $observer) |
26
|
|
|
{ |
27
|
|
|
$observer->getEvent()->getOrder()->collectShipmentAmounts(); |
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Collect discount amounts from quote addresses and apply them to the |
33
|
|
|
* newly created order. |
34
|
|
|
* |
35
|
|
|
* @param Varien_Event_Observer |
36
|
|
|
* @return self |
37
|
|
|
*/ |
38
|
|
|
public function handleSalesConvertQuoteToOrder(Varien_Event_Observer $observer) |
39
|
|
|
{ |
40
|
|
|
$event = $observer->getEvent(); |
41
|
|
|
$order = $event->getOrder(); |
42
|
|
|
$quote = $event->getQuote(); |
43
|
|
|
|
44
|
|
|
$discountAmount = 0.00; |
45
|
|
|
$baseDiscountAmount = 0.00; |
46
|
|
|
foreach ($quote->getAllAddresses() as $address) { |
47
|
|
|
$discountAmount += $address->getDiscountAmount(); |
48
|
|
|
$baseDiscountAmount += $address->getBaseDiscountAmount(); |
49
|
|
|
|
50
|
|
|
// Each address *may* have a discount description but the order |
51
|
|
|
// can only have one. The discount description appears to only apply |
52
|
|
|
// to discounts added with a coupon. OOTB Magento only supports a |
53
|
|
|
// single coupon per order. So, while each address may have a discount |
54
|
|
|
// description, any address that has one will have the same one - |
55
|
|
|
// the one coupon discount that can be applied. As the description |
56
|
|
|
// can be on any, all or none of the addresses, check each address |
57
|
|
|
// for one and take the description from the first address that has one. |
58
|
|
|
if (!$order->hasDiscountDescription() && $address->hasDiscountDescription()) { |
59
|
|
|
$order->setDiscountDescription($address->getDiscountDescription()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$order->setDiscountAmount($discountAmount) |
64
|
|
|
->setBaseDiscountAmount($baseDiscountAmount); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|