Exemplo n.º 1
0
 /**
  * @param $user
  * @param $pass
  * @return ShopgateCustomer
  * @throws ShopgateLibraryException
  */
 public function getCustomer($user, $pass)
 {
     $customerId = $this->getCustomerIdByEmailAndPassword($user, $pass);
     if (!$customerId) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_WRONG_USERNAME_OR_PASSWORD, 'Username or password is incorrect');
     }
     /** @var CustomerCore $customer */
     $customer = new Customer($customerId);
     $shopgateCustomer = new ShopgateCustomer();
     $shopgateCustomer->setCustomerId($customer->id);
     $shopgateCustomer->setCustomerNumber($customer->id);
     $shopgateCustomer->setFirstName($customer->firstname);
     $shopgateCustomer->setLastName($customer->lastname);
     $shopgateCustomer->setGender($this->mapGender($customer->id_gender));
     $shopgateCustomer->setBirthday($customer->birthday);
     $shopgateCustomer->setMail($customer->email);
     $shopgateCustomer->setNewsletterSubscription($customer->newsletter);
     $shopgateCustomer->setCustomerToken(ShopgateCustomerPrestashop::getToken($customer));
     $addresses = array();
     foreach ($customer->getAddresses($this->getPlugin()->getLanguageId()) as $address) {
         $addressItem = new ShopgateAddress();
         $addressItem->setId($address['id_address']);
         $addressItem->setFirstName($address['firstname']);
         $addressItem->setLastName($address['lastname']);
         $addressItem->setCompany($address['company']);
         $addressItem->setStreet1($address['address1']);
         $addressItem->setStreet2($address['address2']);
         $addressItem->setCity($address['city']);
         $addressItem->setZipcode($address['postcode']);
         $addressItem->setCountry($address['country']);
         $addressItem->setState($address['state']);
         $addressItem->setPhone($address['phone']);
         $addressItem->setMobile($address['phone_mobile']);
         if ($address['alias'] == 'Default invoice address') {
             $addressItem->setAddressType(ShopgateAddress::INVOICE);
         } elseif ($address['alias'] == 'Default delivery address') {
             $addressItem->setAddressType(ShopgateAddress::DELIVERY);
         } else {
             $addressItem->setAddressType(ShopgateAddress::BOTH);
         }
         $addresses[] = $addressItem;
     }
     $shopgateCustomer->setAddresses($addresses);
     /**
      * customer groups
      */
     $customerGroups = array();
     if (is_array($customer->getGroups())) {
         foreach ($customer->getGroups() as $customerGroupId) {
             $groupItem = new Group($customerGroupId, $this->getPlugin()->getLanguageId(), $this->getPlugin()->getContext()->shop->id ? $this->getPlugin()->getContext()->shop->id : false);
             $group = new ShopgateCustomerGroup();
             $group->setId($groupItem->id);
             $group->setName($groupItem->name);
             $customerGroups[] = $group;
         }
     }
     $shopgateCustomer->setCustomerGroups($customerGroups);
     return $shopgateCustomer;
 }
Exemplo n.º 2
0
 public function getOrders($customerToken, $customerLanguage, $limit, $offset, $orderDateFrom, $sortOrder)
 {
     $shopgateCustomerModel = new ShopgateCustomerPrestashop();
     $this->_currentCustomer = $shopgateCustomerModel->getCustomerByToken($customerToken);
     if (!$this->_currentCustomer->validateFields(false)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_CUSTOMER_TOKEN_INVALID);
     }
     $orders = $this->getCustomerOrders($this->_currentCustomer->id, $limit, $offset, $orderDateFrom, $sortOrder);
     foreach ($orders as $orderItem) {
         /** @var OrderCore $orderCore */
         $orderCore = new Order($orderItem['id_order']);
         $order = new ShopgateExternalOrder();
         $order->setOrderNumber($orderCore->id);
         $order->setExternalOrderNumber($orderCore->reference);
         $order->setExternalOrderId($orderCore->id);
         /** @var OrderStateCore $orderStatus */
         $orderStatus = new OrderState($orderCore->getCurrentState());
         $order->setStatusName($orderStatus->name[$this->getPlugin()->getLanguageId()]);
         $order->setStatusColor($orderStatus->color);
         $order->setCreatedTime($orderCore->date_add);
         $order->setMail($this->_currentCustomer->email);
         $order->setDeliveryAddress($this->_getAddress($orderCore->id_address_delivery, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setInvoiceAddress($this->_getAddress($orderCore->id_address_invoice, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setItems($this->_getOrderItems($orderCore));
         $order->setExternalCoupons($this->_getCartRules($orderCore));
         /** @var CurrencyCore $currency */
         $currency = Currency::getCurrency($orderCore->id_currency);
         $order->setCurrency($currency['iso_code']);
         $order->setAmountComplete(isset($orderCore->total_paid_tax_incl) ? $orderCore->total_paid_tax_incl : $orderCore->total_paid);
         $order->setIsPaid($orderCore->hasBeenPaid());
         $order->setPaymentMethod($orderCore->payment);
         $order->setIsShippingCompleted($orderCore->hasBeenShipped());
         $order->setShippingCompletedTime($orderCore->hasBeenShipped() ? $orderCore->delivery_date : null);
         $order->setDeliveryNotes($this->_getDeliveryNotes($orderCore));
         $order->setExtraCosts($this->_getExtraCost($orderCore));
         $order->setOrderTaxes($this->_getOrderTaxes());
         $this->_result[] = $order;
     }
     return $this->_result;
 }
Exemplo n.º 3
0
 /**
  * @param string $token
  *
  * @return mixed
  */
 public function getCustomerByToken($token)
 {
     $shopgateCustomerId = ShopgateCustomerPrestashop::getIdShopgateCustomerByFilter('customer_token', $token);
     $shopgateCustomer = new ShopgateCustomerPrestashop($shopgateCustomerId);
     return new Customer($shopgateCustomer->id_customer);
 }