Example #1
0
 /**
  * Prepare object for save
  *
  * @param Varien_Object $object
  * @return Mage_Customer_Model_Resource_Address_Attribute_Backend_Street
  */
 public function beforeSave($object)
 {
     $street = $object->getStreet(-1);
     if ($street) {
         $object->implodeStreetAddress();
     }
     return $this;
 }
Example #2
0
 /**
  * Get billing address request data
  *
  * @param Varien_Object $address
  * @return array
  */
 protected function _getBillingAddress(Varien_Object $address)
 {
     $request = array('billing_first_name' => $address->getFirstname(), 'billing_last_name' => $address->getLastname(), 'billing_city' => $address->getCity(), 'billing_state' => $address->getRegion(), 'billing_zip' => $address->getPostcode(), 'billing_country' => $address->getCountry());
     // convert streets to tow lines format
     $street = Mage::helper('customer/address')->convertStreetLines($address->getStreet(), 2);
     $request['billing_address1'] = isset($street[0]) ? $street[0] : '';
     $request['billing_address2'] = isset($street[1]) ? $street[1] : '';
     return $request;
 }
Example #3
0
 /**
  * Street address workaround: divides address lines into parts by specified keys
  * (keys should go as 3rd, 4th[...] parameters)
  *
  * @param Varien_Object $address
  * @param array $request
  */
 protected function _importStreetFromAddress(Varien_Object $address, array &$to)
 {
     $keys = func_get_args();
     array_shift($keys);
     array_shift($keys);
     $street = $address->getStreet();
     if (!$keys || !$street || !is_array($street)) {
         return;
     }
     $street = Mage::helper('customer/address')->convertStreetLines($address->getStreet(), count($keys));
     $i = 0;
     foreach ($keys as $key) {
         $to[$key] = isset($street[$i]) ? $street[$i] : '';
         $i++;
     }
 }
Example #4
0
 /**
  * Assigning shipping address to soap object
  *
  * @param Varien_Object $shipping
  */
 protected function addShippingAddress($shipping)
 {
     //checking if we have shipping address, in case of virtual order we will not have it
     if ($shipping) {
         $shipTo = new stdClass();
         $shipTo->firstName = $shipping->getFirstname();
         $shipTo->lastName = $shipping->getLastname();
         $shipTo->company = $shipping->getCompany();
         $shipTo->street1 = $shipping->getStreet(1);
         $shipTo->street2 = $shipping->getStreet(2);
         $shipTo->city = $shipping->getCity();
         $shipTo->state = $shipping->getRegion();
         $shipTo->postalCode = $shipping->getPostcode();
         $shipTo->country = $shipping->getCountry();
         $shipTo->phoneNumber = $this->cleanPhoneNum($shipping->getTelephone());
         $this->_request->shipTo = $shipTo;
         Mage::getSingleton('core/session')->setShipping($shipTo);
     }
 }
 /**
  * Adopt specified address object to be compatible with Magento
  *
  * @param Varien_Object $address
  */
 protected function _applyStreetAndRegionWorkarounds(Varien_Object $address)
 {
     // merge street addresses into 1
     if ($address->hasStreet2()) {
         $address->setStreet(implode("\n", array($address->getStreet(), $address->getStreet2())));
         $address->unsStreet2();
     }
     // attempt to fetch region_id from directory
     if ($address->getCountryId() && $address->getRegion()) {
         $regions = Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getRegionCollection()->addRegionCodeOrNameFilter($address->getRegion())->setPageSize(1);
         foreach ($regions as $region) {
             $address->setRegionId($region->getId());
             $address->setExportedKeys(array_merge($address->getExportedKeys(), array('region_id')));
             break;
         }
     }
 }
Example #6
0
 /**
  * Street address workaround: divides address lines into parts by specified keys
  * (keys should go as 3rd, 4th[...] parameters)
  *
  * @param Varien_Object $address
  * @param array $request
  */
 protected function _importStreetFromAddress(Varien_Object $address, array &$to)
 {
     $keys = func_get_args();
     array_shift($keys);
     array_shift($keys);
     $street = $address->getStreet();
     if (!$keys || !$street || !is_array($street)) {
         return;
     }
     foreach ($keys as $key) {
         if ($value = array_pop($street)) {
             $to[$key] = $value;
         }
     }
 }
Example #7
0
 /**
  * Copy address
  * 
  * @param Varien_Object $srcAddress
  * @param Varien_Object $dstAddress
  * @return Innoexts_Warehouse_Helper_Data
  */
 public function copy($srcAddress, $dstAddress)
 {
     $dstAddress->setCountryId($srcAddress->getCountryId());
     $dstAddress->setRegionId($srcAddress->getRegionId());
     $dstAddress->setRegion($srcAddress->getRegion());
     $dstAddress->setCity($srcAddress->getCity());
     $dstAddress->setPostcode($srcAddress->getPostcode());
     $dstAddress->setStreet($srcAddress->getStreet());
     return $this;
 }
Example #8
0
 /**
  * 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;
 }