コード例 #1
0
 /**
  * create dummy customer
  *
  * @param ShopgateCart $cart
  */
 protected function _createCustomer(ShopgateCart $cart)
 {
     /**
      * prepare customer group
      */
     if ($cart->getExternalCustomerId()) {
         /**
          * load exist customer
          */
         $this->getPlugin()->getContext()->customer = new Customer($cart->getExternalCustomerId());
         if (!Validate::isLoadedObject($this->getPlugin()->getContext()->customer)) {
             $this->_addException(ShopgateLibraryException::UNKNOWN_ERROR_CODE, sprintf('Customer with id #%s not found', $cart->getExternalCustomerId()));
         }
     } else {
         /**
          * create dummy customer
          */
         $customerGroup = $this->_getCustomerGroups($cart);
         $this->getPlugin()->getContext()->customer = new Customer();
         $this->getPlugin()->getContext()->customer->lastname = self::DEFAULT_CUSTOMER_LAST_NAME;
         $this->getPlugin()->getContext()->customer->firstname = self::DEFAULT_CUSTOMER_FIRST_NAME;
         $this->getPlugin()->getContext()->customer->email = self::DEFAULT_CUSTOMER_EMAIL;
         $this->getPlugin()->getContext()->customer->passwd = self::DEFAULT_CUSTOMER_PASSWD;
         $this->getPlugin()->getContext()->customer->id_default_group = current($customerGroup->getCustomerGroups())->getId();
         $this->getPlugin()->getContext()->customer->add();
         $this->_isDummyCustomer = true;
     }
     /**
      * add customer to cart
      */
     $this->getPlugin()->getContext()->cart->id_customer = $this->getPlugin()->getContext()->customer->id;
     /**
      * add carrier id
      */
     $shippingModel = new ShopgateShipping($this->getModule());
     $tmpOrder = new ShopgateOrder();
     $tmpOrder->setShippingType($cart->getShippingType() ? $cart->getShippingType() : ShopgateShipping::DEFAULT_PLUGIN_API_KEY);
     $tmpOrder->setShippingGroup($cart->getShippingGroup());
     $tmpOrder->setShippingInfos($cart->getShippingInfos());
     /** @var CarrierCore $carrierItem */
     $carrierItem = new Carrier($shippingModel->getCarrierIdByApiOrder($tmpOrder));
     if (!Validate::isLoadedObject($carrierItem)) {
         $this->_addException(ShopgateLibraryException::UNKNOWN_ERROR_CODE, sprintf('Invalid carrier ID #%s', $shippingModel->getCarrierIdByApiOrder($tmpOrder)));
     }
     $this->getPlugin()->getContext()->cart->id_carrier = $carrierItem->id;
     $this->getPlugin()->getContext()->cart->save();
 }