/** * Assign data to info model instance * Save capayable customer * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $quote = $this->getInfoInstance()->getQuote(); $address = $quote->getBillingAddress(); if (!$quote->getCustomerMiddlename()) { $quote->setCustomerMiddlename($data->getCustomerMiddlename()); } if (!$quote->getCustomerGender()) { $quote->setCustomerGender($data->getCustomerGender()); } // Convert date format $dob = $quote->getCustomerDob() ? $quote->getCustomerDob() : $data->getCustomerDob(); $dob = Mage::app()->getLocale()->date($dob, null, null, false)->toString('yyyy-MM-dd 00:00:00'); $data->setCustomerDob($dob); $quote->setCustomerDob($dob); $capayableCustomer = Mage::getModel('capayable/customer')->loadByEmail($quote->getCustomerEmail()); /** * If capayable customer doesn't exist fill new customer data from quote data. * Otherwise rewrite saved customer fields from form data. */ if (!$capayableCustomer->getId()) { $capayableCustomer->setCustomerEmail($quote->getCustomerEmail())->setCustomerLastname($quote->getCustomerLastname())->setCustomerMiddlename($quote->getCustomerMiddlename())->setCustomerGender($quote->getCustomerGender())->setCustomerDob($quote->getCustomerDob())->setStreet($data->getStreet())->setHouseNumber((int) $data->getHouseNumber())->setHouseSuffix($data->getHouseSuffix())->setPostcode($data->getPostcode())->setCity($data->getCity())->setCountryId($address->getCountryId())->setTelephone($address->getTelephone())->setFax($address->getFax())->setIsCorporation($data->getIsCorporation())->setIsSoleProprietor($data->getIsSoleProprietor())->setCorporationName($data->getCorporationName())->setCocNumber($data->getCocNumber()); } else { $capayableCustomer->addData($data->getData()); } // Validate capayable customer required fields $result = $capayableCustomer->validate(); if (true !== $result && is_array($result)) { throw new Mage_Payment_Model_Info_Exception(implode(', ', $result)); } // Save capayable customer to 'capayable/customer' table $capayableCustomer->save(); $this->getInfoInstance()->addData($data->getData()); return $this; }