Failed Conditions
Pull Request — develop (#1)
by Carlo
02:35
created

QuoteCustomer::_setCustomerDataAndValidate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 9.4286
cc 3
eloc 11
nc 4
nop 0
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
     * @param array $this->_data
0 ignored issues
show
Bug introduced by
There is no parameter named $this->_data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
55
     *
56
     * @return date|bool
57
     *
58
     */
59
    private function _setCustomerOptionalData()
60
    {
61
        $dob = false;
62
        if (isset($this->_data['dob'])) {
63
            $dob = Mage::app()->getLocale()->date($this->_data['dob'], null, null, false)->toString(
64
                'yyyy-MM-dd'
65
            );
66
67
            $this->_quote->setCustomerDob($dob);
68
        }
69
70
        if (isset($this->_data['taxvat'])) {
71
            $this->_quote->setCustomerTaxvat($this->_data['taxvat']);
72
        }
73
74
        if (isset($this->_data['gender'])) {
75
            $this->_quote->setCustomerGender($this->_data['gender']);
76
        }
77
78
        return $dob;
79
    }
80
    
81
    private function _setCustomerDataAndValidate()
82
    {
83
        $customer = Mage::getModel($this->_data['model']);
84
        $this->_quote->setPasswordHash($customer->encryptPassword($this->_data['password']));
85
        $customer->setData($this->_data);
86
        $dob = $this->_quote->getCustomerDob();
87
88
        if ($dob) {
89
            $customer->setDob($dob);
90
        }
91
92
        $validationResult = $customer->validate();
93
94
        if ($validationResult === true) {
95
            $this->_quote->getBillingAddress()->setEmail($this->_data['email']);
96
            Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $this->_quote);
97
        }
98
    }
99
}
100