Ejemplo n.º 1
0
 /**
  * @param Mage_Customer_Model_Address_Abstract|Mage_Sales_Model_Abstract $magentoObject
  * @param ShopgateOrder|ShopgateAddress|ShopgateCustomer                 $shopgateObject
  * @return mixed
  */
 public function setCustomFields($magentoObject, $shopgateObject)
 {
     foreach ($shopgateObject->getCustomFields() as $field) {
         $magentoObject->setData($field->getInternalFieldName(), $field->getValue());
     }
     return $magentoObject;
 }
Ejemplo n.º 2
0
 /**
  * @param $address
  * @param $customer
  * @return int
  * @throws ShopgateLibraryException
  */
 public function createAddress(ShopgateAddress $address, $customer)
 {
     /** @var AddressCore | Address $addressModel */
     $addressItem = new Address();
     $addressItem->id_customer = $customer->id;
     $addressItem->lastname = $address->getLastName();
     $addressItem->firstname = $address->getFirstName();
     if ($address->getCompany()) {
         $addressItem->company = $address->getCompany();
     }
     $addressItem->address1 = $address->getStreet1();
     if ($address->getStreet2()) {
         $addressItem->address2 = $address->getStreet2();
     }
     $addressItem->city = $address->getCity();
     $addressItem->postcode = $address->getZipcode();
     if (!Validate::isLanguageIsoCode($address->getCountry())) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, 'invalid country code: ' . $address->getCountry(), true);
     }
     $addressItem->id_country = Country::getByIso($address->getCountry());
     /**
      * prepare states
      */
     $stateParts = explode('-', $address->getState());
     if (count($stateParts) == 2) {
         $address->setState($stateParts[1]);
     }
     if ($address->getState() && !Validate::isStateIsoCode($address->getState())) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, 'invalid state code: ' . $address->getState(), true);
     } else {
         $addressItem->id_state = State::getIdByIso($address->getState());
     }
     $addressItem->alias = $address->getIsDeliveryAddress() ? $this->getModule()->l('Default delivery address') : $this->getModule()->l('Default');
     $addressItem->alias = $address->getIsInvoiceAddress() ? $this->getModule()->l('Default invoice address') : $this->getModule()->l('Default');
     $addressItem->phone = $address->getPhone();
     $addressItem->phone_mobile = $address->getMobile();
     $shopgateCustomFieldsHelper = new ShopgateCustomFieldsHelper();
     $shopgateCustomFieldsHelper->saveCustomFields($addressItem, $address->getCustomFields());
     $validateMessage = $addressItem->validateFields(false, true);
     if ($validateMessage !== true) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, $validateMessage, true);
     }
     $addressItem->save();
     return $addressItem->id;
 }