-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataProcessor.php
More file actions
104 lines (85 loc) · 3.34 KB
/
DataProcessor.php
File metadata and controls
104 lines (85 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* This source file is available under GNU General Public License version 3 (GPLv3)
*
* Full copyright and license information is available in LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Asioso GmbH (https://www.asioso.com)
*
*/
namespace AppBundle\Ecommerce\DataProcessor;
use PayoneBundle\Model\AbstractDataProcessor;
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\AbstractCart;
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\ICartItem;
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractPaymentInformation;
use Pimcore\Model\DataObject\Product;
/**
* Class DataProcessor
* @package AppBundle\Ecommerce
*/
class DataProcessor extends AbstractDataProcessor
{
/**
* @param AbstractPaymentInformation $information
* @param AbstractCart $cart
* @return array
* @throws \Exception
*/
public function retrievePersonalData(AbstractPaymentInformation &$information, AbstractCart &$cart)
{
$object = $information->getObject();
$data = array(
self::PERSONAL_FIRSTNAME => $object->get('customerFirstname'),
self::PERSONAL_LASTNAME => $object->get('customerLastname'),
self::PERSONAL_STREET => $object->get('customerStreet'),
self::PERSONAL_ZIP => $object->get('customerZip'),
self::PERSONAL_CITY => $object->get('customerCity'),
self::PERSONAL_COUNTRY => $object->get('customerCountry'),
self::PERSONAL_EMAIL => $object->get('customerEmail'),
);
if ($company = $object->get('customerCompany')) {
$data[self::PERSONAL_COMPANY] = $company;
}
return $data;
}
/**
* @param AbstractPaymentInformation $information
* @param AbstractCart $cart
* @return array
*
* @throws \Exception
*/
public function retrieveShippingData(AbstractPaymentInformation &$information, AbstractCart &$cart)
{
$object = $information->getObject();
$data = array(
self::SHIPPING_FIRSTNAME => $object->get('deliveryFirstname'),
self::SHIPPING_LASTNAME => $object->get('deliveryLastname'),
self::SHIPPING_STREET => $object->get('deliveryStreet'),
self::SHIPPING_ZIP => $object->get('deliveryZip'),
self::SHIPPING_CITY => $object->get('deliveryCity'),
self::SHIPPING_COUNTRY => $object->get('deliveryCountry'),
);
if ($object->get('deliveryCompany') != null) {
$data[self::SHIPPING_COMPANY] = $object->get('company');
}
return $data;
}
/**
* return an array ['id'=> <itemId>, 'name'=><itemName>]
* is used to generate invoice data
* @param $cartItem
* @return array
*/
public function retrieveInvoiceData($cartItem)
{
if($cartItem instanceof ICartItem){
$product = $cartItem->getProduct();
if($product instanceof Product){
return array(self::INVOICE_ITEM_ID=> $product->getId(), self::INVOICE_ITEM_NAME=> $product->getName());
}
throw new \InvalidArgumentException(sprintf('%s is not supported by %s', get_class($product), get_class($this)));
}
throw new \InvalidArgumentException(sprintf('%s is not supported by %s', get_class($cartItem), get_class($this)));
}
}