Exemple #1
0
 /**
  * Fetches any related customer_group to the given cart object
  *
  * @param ShopgateCart $cart
  * @param int          $websiteId
  *
  * @return array
  */
 protected function _getCustomerGroups(ShopgateCart $cart, $websiteId)
 {
     /** @var Mage_Customer_Model_Customer $customer */
     $customer = Mage::getModel('customer/customer');
     $externalCustomerId = $cart->getExternalCustomerId();
     if ($externalCustomerId) {
         $customer->load($externalCustomerId);
     } else {
         if ($cart->getDeliveryAddress() && $cart->getDeliveryAddress()->getMail()) {
             $customer->setWebsiteId($websiteId)->loadByEmail($cart->getDeliveryAddress()->getMail());
         } else {
             if ($cart->getInvoiceAddress() && $cart->getInvoiceAddress()->getMail()) {
                 $customer->setWebsiteId($websiteId)->loadByEmail($cart->getInvoiceAddress()->getMail());
             }
         }
     }
     if (!$externalCustomerId && $customer->getId()) {
         $cart->setExternalCustomerId($customer->getId());
     }
     return Mage::helper('shopgate/customer')->getShopgateCustomerGroups($customer);
 }
 /**
  * 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();
 }