Example #1
0
 /**
  * @param ShopgateCartBase $order
  * @return $this
  */
 public function init(ShopgateCartBase $order)
 {
     ShopgateLogger::getInstance()->log("# " . __FUNCTION__, ShopgateLogger::LOGTYPE_DEBUG);
     $this->_order = $order;
     $this->_carrier = $this->_fetchCarrier($order->getShippingGroup());
     return $this;
 }
Example #2
0
 /**
  * Serve the method name
  *
  * @param ShopgateCartBase $order
  * @return string
  */
 protected function _fetchMethod(ShopgateCartBase $order)
 {
     ShopgateLogger::getInstance()->log("# " . __METHOD__, ShopgateLogger::LOGTYPE_DEBUG);
     $response = $order->getShippingInfos()->getApiResponse();
     if (!isset($response['MailService'])) {
         try {
             $methodOriginCode = $response['SvcDescription'];
         } catch (Exception $e) {
             Mage::logException(new Exception('No shipping_method in response available'));
             ShopgateLogger::getInstance()->log("  There is no shipping method available in the response [Not Mailservice nor SvcDescription contains any data]", ShopgateLogger::LOGTYPE_DEBUG);
             /* TODO not only the method should get corrected also the carrier */
             return Shopgate_Framework_Model_Shopgate_Shipping_Mapper_Method_Abstract::DEFAULT_SHIPPING_METHOD;
         }
     } else {
         $methodOriginCode = $response['MailService'];
     }
     return $this->_mapShippingMethod($methodOriginCode);
 }
Example #3
0
 /**
  * @param ShopgateCartBase $order
  * @param ShopgateAddress  $address
  * @param bool             $saveInAddressBook
  * @return array
  */
 public function createAddressData($order, $address, $saveInAddressBook = false)
 {
     ShopgateLogger::getInstance()->log('_createAddressData', ShopgateLogger::LOGTYPE_DEBUG);
     $phoneNumber = $order->getMobile();
     if (empty($phoneNumber)) {
         $phoneNumber = $order->getPhone();
     }
     if (empty($phoneNumber)) {
         $phoneNumber = "n.a.";
     }
     $region = Mage::helper('shopgate/customer')->getMagentoRegionByShopgateAddress($address);
     $prefix = "Mr.";
     if ($address->getGender() == "f") {
         $prefix = "Mrs.";
     }
     $prefix = $this->_getHelper()->__($prefix);
     $addressData = array('prefix' => $prefix, 'company' => $address->getCompany(), 'firstname' => $address->getFirstName(), 'lastname' => $address->getLastName(), 'street' => $address->getStreet1() . ($address->getStreet2() ? "\n" . $address->getStreet2() : ""), 'city' => $address->getCity(), 'postcode' => $address->getZipcode(), 'telephone' => $phoneNumber, 'email' => $order->getMail(), 'country_id' => $address->getCountry(), 'region_id' => $region->getId(), 'save_in_address_book' => $saveInAddressBook);
     $customFields = array();
     foreach ($address->getCustomFields() as $field) {
         $customFields[] = array($field->getInternalFieldName() => $field->getValue());
     }
     $addressData = array_merge($addressData, $customFields);
     return $addressData;
 }
Example #4
0
 /**
  * Sets the correct Shipping Carrier and Method
  * in relation to
  *        ShopgateOrder->{shipping_group} [carrier]
  *        ShopgateOrder->{shipping_info}    [method]
  *
  * @param Mage_Sales_Model_Quote_Address $shippingAddress
  * @param ShopgateCartBase               $order
  */
 public function setShippingMethod(Mage_Sales_Model_Quote_Address $shippingAddress, ShopgateCartBase $order)
 {
     /* dont set shipping method when the order does not contain any shipping information (e.g. checkCart) */
     if (!$order->getShippingGroup()) {
         ShopgateLogger::getInstance()->log("# setShippingMethod skipped, no Shipping information in " . get_class($order) . " available", ShopgateLogger::LOGTYPE_DEBUG);
         return;
     }
     ShopgateLogger::getInstance()->log("# Start of setShippingMethod process", ShopgateLogger::LOGTYPE_DEBUG);
     $mapper = Mage::getModel('shopgate/shopgate_shipping_mapper')->init($shippingAddress, $order);
     $shippingAddress->setShippingMethod($mapper->getCarrier() . '_' . $mapper->getMethod());
     ShopgateLogger::getInstance()->log("  Shipping method set: '" . $shippingAddress->getShippingMethod() . "'", ShopgateLogger::LOGTYPE_DEBUG);
     ShopgateLogger::getInstance()->log("# End of setShippingMethod process", ShopgateLogger::LOGTYPE_DEBUG);
 }
Example #5
0
 /**
  * Add coupon from this system to quote
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param ShopgateCartBase       $order
  *
  * @return Mage_Sales_Model_Quote
  * @throws ShopgateLibraryException
  */
 protected function _setQuoteShopCoupons($quote, $order)
 {
     if (count($order->getExternalCoupons()) > 1) {
         throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_TOO_MANY_COUPONS);
     }
     foreach ($order->getExternalCoupons() as $coupon) {
         /* @var $coupon ShopgateShopgateCoupon */
         $couponInfos = $this->jsonDecode($coupon->getInternalInfo(), true);
         if ($order instanceof ShopgateOrder) {
             if (!$coupon->getInternalInfo()) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_NOT_VALID, 'Field "internal_info" is empty.');
             }
             /** @var Mage_SalesRule_Model_Coupon $mageCoupon */
             if ($this->_getConfigHelper()->getIsMagentoVersionLower1410()) {
                 $mageCoupon = Mage::getModel('salesrule/rule')->load($couponInfos["coupon_id"]);
             } else {
                 $mageCoupon = Mage::getModel('salesrule/coupon')->load($couponInfos["coupon_id"]);
             }
             $count = (int) $mageCoupon->getTimesUsed();
             $count--;
             $mageCoupon->setTimesUsed($count);
             $mageCoupon->save();
         }
         $quote->setCouponCode($coupon->getCode());
         foreach ($quote->getAllAddresses() as $address) {
             $address->setCouponCode($coupon->getCode());
         }
         $quote->setTotalsCollectedFlag(false);
         $quote->collectTotals();
         if ($this->_errorOnInvalidCoupon) {
             if ($coupon->getCode() != $quote->getCouponCode()) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_NOT_VALID, 'Code transferred by Shopgate"' . $coupon->getCode() . '" != "' . $quote->getCouponCode() . '" code in Magento');
             }
         }
         $quote->save();
     }
     return $quote;
 }