| 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 |  |  | use Magefix\Fixture\Builder\Helper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class QuoteCustomer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package Magefix\Fixture\Builder\Helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @author  Carlo Tasca <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class QuoteCustomer implements Helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $_builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var Mage_Sales_Model_Quote | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $_quote; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $_data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function __construct(Builder $_builder, Mage_Sales_Model_Quote $_quote, array $_data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->_builder = $_builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->_quote   = $_quote; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->_data    = $_data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function setupMethodGuest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->_quote->setCustomerId(null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ->setCustomerEmail($this->_quote->getBillingAddress()->getEmail()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->setCustomerIsGuest(true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function setupMethodRegister() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->_setupCustomerOptionalData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->_setupCustomerDataAndValidate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @return date|bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     private function _setupCustomerOptionalData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 _setupCustomerDataAndValidate() | 
            
                                                        
            
                                    
            
            
                | 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 |  |  |  |