1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magefix\Fixture\Builder\Helper; |
4
|
|
|
|
5
|
|
|
use Mage; |
6
|
|
|
use Mage_Customer_Model_Group; |
7
|
|
|
use Mage_Sales_Model_Quote; |
8
|
|
|
use Magefix\Fixture\Builder; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class QuoteCustomer |
12
|
|
|
* |
13
|
|
|
* @package Magefix\Fixture\Builder\Helper |
14
|
|
|
* @author Carlo Tasca <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class QuoteCustomer |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Builder |
20
|
|
|
*/ |
21
|
|
|
private $_builder; |
22
|
|
|
/** |
23
|
|
|
* @var Mage_Sales_Model_Quote |
24
|
|
|
*/ |
25
|
|
|
private $_quote; |
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $_data; |
30
|
|
|
|
31
|
|
|
public function __construct(Builder $_builder, Mage_Sales_Model_Quote $_quote, array $_data) |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
$this->_builder = $_builder; |
35
|
|
|
$this->_quote = $_quote; |
36
|
|
|
$this->_data = $_data; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function setMethodGuest() |
40
|
|
|
{ |
41
|
|
|
$this->_quote->setCustomerId(null) |
42
|
|
|
->setCustomerEmail($this->_quote->getBillingAddress()->getEmail()) |
43
|
|
|
->setCustomerIsGuest(true) |
44
|
|
|
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setMethodRegister() |
48
|
|
|
{ |
49
|
|
|
$this->_setCustomerOptionalData(); |
50
|
|
|
$this->_setCustomerDataAndValidate(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
* @return date|bool |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
private function _setCustomerOptionalData() |
59
|
|
|
{ |
60
|
|
|
$dob = false; |
61
|
|
|
if (isset($this->_data['dob'])) { |
62
|
|
|
$dob = Mage::app()->getLocale()->date($this->_data['dob'], null, null, false)->toString( |
63
|
|
|
'yyyy-MM-dd' |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->_quote->setCustomerDob($dob); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (isset($this->_data['taxvat'])) { |
70
|
|
|
$this->_quote->setCustomerTaxvat($this->_data['taxvat']); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (isset($this->_data['gender'])) { |
74
|
|
|
$this->_quote->setCustomerGender($this->_data['gender']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $dob; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function _setCustomerDataAndValidate() |
81
|
|
|
{ |
82
|
|
|
$customer = Mage::getModel($this->_data['model']); |
83
|
|
|
$this->_quote->setPasswordHash($customer->encryptPassword($this->_data['password'])); |
84
|
|
|
$customer->setData($this->_data); |
85
|
|
|
$dob = $this->_quote->getCustomerDob(); |
86
|
|
|
|
87
|
|
|
if ($dob) { |
88
|
|
|
$customer->setDob($dob); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$validationResult = $customer->validate(); |
92
|
|
|
|
93
|
|
|
if ($validationResult === true) { |
94
|
|
|
$this->_quote->getBillingAddress()->setEmail($this->_data['email']); |
95
|
|
|
Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $this->_quote); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|