Esempio n. 1
0
 /**
  * Fills in the form data array
  *
  * @param  unknown        $object
  * @return array
  */
 protected function createFormDataArray($object)
 {
     return array("label" => $object->getLabel(), "title" => $object->getTitleId(), "firstname" => $object->getFirstname(), "lastname" => $object->getLastname(), "address1" => $object->getAddress1(), "address2" => $object->getAddress2(), "address3" => $object->getAddress3(), "zipcode" => $object->getZipcode(), "city" => $object->getCity(), "country" => $object->getCountryId(), "cellphone" => $object->getCellphone(), "phone" => $object->getPhone(), "company" => $object->getCompany());
 }
 /**
  * Exports the customer
  */
 protected function exportCustomer()
 {
     if (is_null($this->BillingAddress)) {
         throw new PlentymarketsExportEntityException('The customer with the email address »' . $this->Customer->getEmail() . '« could not be exported (no billing address)', 2100);
     }
     try {
         if ($this->BillingAddress instanceof \Shopware\Models\Customer\Billing) {
             $this->PLENTY_customerID = PlentymarketsMappingController::getCustomerBillingAddressByShopwareID($this->BillingAddress->getId());
         } else {
             if ($this->BillingAddress instanceof \Shopware\Models\Order\Billing) {
                 $this->PLENTY_customerID = PlentymarketsMappingController::getCustomerByShopwareID($this->BillingAddress->getId());
             }
         }
         // Already exported
         return;
     } catch (PlentymarketsMappingExceptionNotExistant $E) {
     }
     // Logging
     PlentymarketsLogger::getInstance()->message('Export:Customer', 'Export of the customer with the number »' . $this->getCustomerNumber() . '«');
     $city = trim($this->BillingAddress->getCity());
     $street_arr = PlentymarketsUtils::extractStreetAndHouseNo($this->BillingAddress->getStreet());
     if (isset($street_arr['street']) && strlen($street_arr['street']) > 0) {
         $streetName = $street_arr['street'];
     } else {
         $streetName = trim($this->BillingAddress->getStreet());
     }
     if (isset($street_arr['houseNo']) && strlen($street_arr['houseNo']) > 0) {
         $streetHouseNumber = $street_arr['houseNo'];
     } else {
         //no house number was found in the street string
         $streetHouseNumber = '';
     }
     $zip = trim($this->BillingAddress->getZipCode());
     if (empty($city)) {
         $city = PlentymarketsConfig::getInstance()->get('CustomerDefaultCity');
     }
     if (!isset($streetHouseNumber) || $streetHouseNumber == '') {
         $streetHouseNumber = PlentymarketsConfig::getInstance()->get('CustomerDefaultHouseNumber');
     }
     if (!isset($streetName) || $streetName == '') {
         $streetName = PlentymarketsConfig::getInstance()->get('CustomerDefaultStreet');
     }
     if ($zip == '') {
         $zip = PlentymarketsConfig::getInstance()->get('CustomerDefaultZipcode');
     }
     $Request_SetCustomers = new PlentySoapRequest_SetCustomers();
     $Request_SetCustomers->Customers = array();
     $Object_SetCustomersCustomer = new PlentySoapObject_Customer();
     $Object_SetCustomersCustomer->City = $city;
     $Object_SetCustomersCustomer->Company = $this->BillingAddress->getCompany();
     $Object_SetCustomersCustomer->CountryID = $this->getBillingCountryID();
     // int
     $Object_SetCustomersCustomer->CustomerClass = $this->getCustomerClassId();
     $Object_SetCustomersCustomer->CustomerNumber = $this->getCustomerNumber();
     // string
     $Object_SetCustomersCustomer->CustomerSince = $this->Customer->getFirstLogin()->getTimestamp();
     // int
     $Object_SetCustomersCustomer->Email = $this->Customer->getEmail();
     // string
     $Object_SetCustomersCustomer->ExternalCustomerID = PlentymarketsUtils::getExternalCustomerID($this->Customer->getId());
     // string
     $Object_SetCustomersCustomer->FormOfAddress = $this->getBillingFormOfAddress();
     // string
     $Object_SetCustomersCustomer->Fax = $this->BillingAddress->getFax();
     $Object_SetCustomersCustomer->FirstName = $this->BillingAddress->getFirstName();
     $Object_SetCustomersCustomer->HouseNo = $streetHouseNumber;
     $Object_SetCustomersCustomer->IsBlocked = !$this->Customer->getActive();
     $Object_SetCustomersCustomer->Newsletter = (int) $this->Customer->getNewsletter();
     $Object_SetCustomersCustomer->PayInvoice = true;
     // boolean
     $Object_SetCustomersCustomer->Street = $streetName;
     $Object_SetCustomersCustomer->Surname = $this->BillingAddress->getLastName();
     $Object_SetCustomersCustomer->Telephone = $this->BillingAddress->getPhone();
     $Object_SetCustomersCustomer->VAT_ID = $this->BillingAddress->getVatId();
     $Object_SetCustomersCustomer->ZIP = $zip;
     // Store id
     try {
         $Object_SetCustomersCustomer->StoreID = PlentymarketsMappingController::getShopByShopwareID($this->Customer->getShop()->getId());
         $Object_SetCustomersCustomer->Language = strtolower(substr($this->Customer->getShop()->getLocale()->getLocale(), 0, 2));
     } catch (PlentymarketsMappingExceptionNotExistant $E) {
     }
     // Customer class
     if ($this->Customer->getGroup()->getId() > 0) {
         try {
             $Object_SetCustomersCustomer->CustomerClass = PlentymarketsMappingController::getCustomerClassByShopwareID($this->Customer->getGroup()->getId());
         } catch (PlentymarketsMappingExceptionNotExistant $E) {
         }
     }
     $Request_SetCustomers->Customers[] = $Object_SetCustomersCustomer;
     $Response_SetCustomers = PlentymarketsSoapClient::getInstance()->SetCustomers($Request_SetCustomers);
     if (!$Response_SetCustomers->Success) {
         throw new PlentymarketsExportEntityException('The customer with the number »' . $this->getCustomerNumber() . '« could not be exported', 2110);
     }
     if ($Response_SetCustomers->ResponseMessages->item[0]->Code == 100 || $Response_SetCustomers->ResponseMessages->item[0]->Code == 200) {
         $this->PLENTY_customerID = (int) $Response_SetCustomers->ResponseMessages->item[0]->SuccessMessages->item[0]->Value;
         if ($this->BillingAddress instanceof \Shopware\Models\Customer\Billing) {
             PlentymarketsMappingController::addCustomerBillingAddress($this->BillingAddress->getId(), $this->PLENTY_customerID);
         } else {
             if ($this->BillingAddress instanceof \Shopware\Models\Order\Billing) {
                 PlentymarketsMappingController::addCustomer($this->BillingAddress->getId(), $this->PLENTY_customerID);
             }
         }
     }
 }