Exemplo n.º 1
0
 /**
  * Mage_Sales_Model_Quote_Address caches items after each collectTotals call. Some extensions calls collectTotals
  * after adding new item to quote in observers. So we need clear this cache before adding new item to quote.
  */
 private function clearQuoteItemsCache()
 {
     foreach ($this->quote->getAllAddresses() as $address) {
         /** @var $address Mage_Sales_Model_Quote_Address */
         $address->unsetData('cached_items_all');
         $address->unsetData('cached_items_nominal');
         $address->unsetData('cached_items_nonominal');
     }
 }
Exemplo n.º 2
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return array
  */
 public function detectWorstAddressScoreByQuote(Mage_Sales_Model_Quote $quote)
 {
     $quoteAddresses = $quote->getAllAddresses();
     $addressScores = array();
     foreach ($quoteAddresses as $address) {
         /** @var $address Mage_Sales_Model_Quote_Address */
         $addressScores[] = $address->getPayoneAddresscheckScore();
     }
     return $this->detectWorstScore($addressScores);
 }
Exemplo n.º 3
0
 /**
  * Gets a PakjeGemak address for either a quote or an order object.
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  *
  * @return false|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|TIG_MyParcel2014_Model_Shipment
  */
 public function getPgAddress($object)
 {
     /**
      * Get all addresses for the specified object.
      */
     if ($object instanceof Mage_Sales_Model_Quote) {
         $addressCollection = $object->getAllAddresses();
     } elseif ($object instanceof Mage_Sales_Model_Order) {
         $addressCollection = $object->getAddressesCollection();
     } elseif ($object instanceof TIG_MyParcel2014_Model_Shipment) {
         $order = $object->getOrder();
         if (!$order) {
             return false;
         }
         $addressCollection = $order->getAddressesCollection();
     } else {
         return false;
     }
     /**
      * Go through each address and check if it's a PakjeGemak address.
      *
      * @var Mage_Sales_Model_Quote_Address|Mage_Sales_Model_Order_Address $address
      */
     $pgAddress = false;
     foreach ($addressCollection as $address) {
         if ($address->getAddressType() == self::PG_ADDRESS_TYPE) {
             $pgAddress = $address;
             break;
         }
     }
     /**
      * Return the PakjeGemak address or false if none was found.
      */
     return $pgAddress;
 }
 /**
  * Determine if taxes can be collected for the quote.
  *
  * @param Mage_Sales_Model_Quote
  * @return self
  * @throws EbayEnterprise_Tax_Exception_Collector_InvalidQuote_Exception If the quote is not valid for making a tax request.
  */
 protected function _validateQuote(Mage_Sales_Model_Quote $quote)
 {
     // At a minimum, the quote must have at least one item and a billing
     // address with usable information. Currently, a spot check of address
     // data *should* be useful enough to separate a complete address from
     // an incomplete address.
     $billingAddress = $quote->getBillingAddress();
     if ($quote->getItemsCount() && $billingAddress->getFirstname() && $billingAddress->getLastname() && $billingAddress->getStreetFull() && $billingAddress->getCountryId()) {
         return $this->_validateAddresses($quote->getAllAddresses());
     }
     throw Mage::exception('EbayEnterprise_Tax_Exception_Collector_InvalidQuote', 'Quote invalid for tax collection.');
 }
Exemplo n.º 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;
 }
Exemplo n.º 6
0
 /**
  * Removes a saved PakjeGemak address from the quote.
  *
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return $this
  * @throws Exception
  */
 public function removePgAddress(Mage_Sales_Model_Quote $quote)
 {
     if ($quote) {
         if ($quote != '{}') {
             $addresses = $quote->getAllAddresses();
             /** @var Mage_Sales_Model_Quote_Address $address */
             foreach ($addresses as $address) {
                 if ($address->getAddressType() == TIG_MyParcel2014_Helper_Data::PG_ADDRESS_TYPE) {
                     $address->delete();
                 }
             }
         }
     }
     return $this;
 }