public function setUp()
 {
     // Mock session storage for previously collected quantity results
     $this->_inventorySession = $this->getModelMockBuilder('ebayenterprise_inventory/session')->setMethods(['getQuantityResults', 'setQuantityResults', 'getResultsCollectedFor', 'setResultsCollectedFor'])->disableOriginalConstructor()->getMock();
     // Mock of the sdk helper for getting new quantity results from the API
     $this->_quantitySdkHelper = $this->getHelperMock('ebayenterprise_inventory/quantity_sdk', ['requestQuantityForItems']);
     // A quantity results stub, expected to be returned by the session or
     // sdk helper.
     $this->_quantityResults = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->setMethods(['checkResultsApplyToItems'])->getMock();
     // Stub quote object to collect quantity records for.
     $this->_quote = $this->getModelMock('sales/quote', ['getAllItems']);
     // Stub quote item that should be sent to the inventory service.
     $this->_quoteItem = $this->getModelMock('sales/quote_item', []);
     // Quote items and filtered quote items allow tests to distinguish
     // between all items in the quote and just items that matter to the
     // inventory service. All quote items includes an additional quote item
     // that is not expected to be sent to the quantity API.
     $this->_quoteItems = [$this->_quoteItem, $this->getModelMock('sales/quote_item', [])];
     $this->_filteredQuoteItems = [$this->_quoteItem];
     // Stub quote to return all quote items.
     $this->_quote->expects($this->any())->method('getAllItems')->will($this->returnValue($this->_quoteItems));
     // Stub filtering from the full quote items down to the filtered
     // array of quote items. Tests that expect a list of items that matter
     // to the inventory service can expect the filted quote items array
     // instead of the unfiltered quote items array.
     $this->_itemSelection = $this->getHelperMock('ebayenterprise_inventory/item_selection', ['selectFrom']);
     $this->_itemSelection->expects($this->any())->method('selectFrom')->with($this->identicalTo($this->_quoteItems))->will($this->returnValue($this->_filteredQuoteItems));
     // Mock helper for calculating item quantities.
     $this->_quantityHelper = $this->getHelperMock('ebayenterprise_inventory/quantity', ['calculateTotalQuantitiesBySku']);
     $this->_currentItemQuantityData = ['a-sku' => 100];
     $this->_quantityHelper->expects($this->any())->method('calculateTotalQuantitiesBySku')->with($this->_filteredQuoteItems)->will($this->returnValue($this->_currentItemQuantityData));
     $this->_quantityCollector = Mage::getModel('ebayenterprise_inventory/quantity_collector', ['quantity_sdk_helper' => $this->_quantitySdkHelper, 'quantity_helper' => $this->_quantityHelper, 'item_selection' => $this->_itemSelection, 'inventory_session' => $this->_inventorySession]);
 }
 /**
  * add birthdate to params list, if it is available
  *
  * @param Mage_Sales_Model_Quote $quote Quote
  * @return array Either empty or with birthdate
  */
 public function convertBirthdate($quote)
 {
     if (is_null($quote->getCustomerDob())) {
         return array();
     }
     return array('GEBURTSDATUM' => Mage::getModel('core/date')->date('d.m.Y', $quote->getCustomerDob()));
 }
Exemplo n.º 3
0
 protected function resetQuote(Mage_Sales_Model_Quote $quote)
 {
     if (!$quote->getData('__applied_rules_reset__')) {
         $quote->setAppliedRuleIds('');
         $quote->setData('__applied_rules_reset__', true);
     }
 }
Exemplo n.º 4
0
 /**
  * Check whether method is available
  *
  * @param Mage_Sales_Model_Quote|null $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     /* custom code written to round price here as roundPrice function was changed */
     $_grand_price = Mage::app()->getStore()->roundPrice($quote->getGrandTotal());
     $_grand_price = round($_grand_price, 2);
     return parent::isAvailable($quote) && !empty($quote) && $_grand_price == 0;
 }
Exemplo n.º 5
0
 protected function setUp()
 {
     parent::setUp();
     $quote = new Mage_Sales_Model_Quote();
     $quote->load('test01', 'reserved_order_id');
     Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId());
 }
Exemplo n.º 6
0
 /**
  * Add error message if estimation has error
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return $this
  */
 protected function _addErrorMessage($quote)
 {
     if ($quote->getData('estimate_tax_error')) {
         $this->_getErrorsHelper()->addErrorMessage($quote);
     }
     return $this;
 }
Exemplo n.º 7
0
 protected function _afterLoad()
 {
     $productCollection = $this->_getProductCollection();
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($this->_quote) {
             $item->setQuote($this->_quote);
         }
         if (!$product) {
             $item->isDeleted(true);
             $recollectQuote = true;
             continue;
         }
         if ($item->getSuperProductId()) {
             $superProduct = $productCollection->getItemById($item->getSuperProductId());
         } else {
             $superProduct = null;
         }
         $itemProduct = clone $product;
         if ($superProduct) {
             $itemProduct->setSuperProduct($superProduct);
             $item->setSuperProduct($superProduct);
         }
         $item->importCatalogProduct($itemProduct);
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Convert the resource model collection to an array
  *
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return array
  */
 public function prepareCollection(Mage_Sales_Model_Quote $quote)
 {
     // Store current state
     $actionType = $this->getActionType();
     $operation = $this->getOperation();
     // Change state
     $this->setActionType(self::ACTION_TYPE_COLLECTION);
     $this->setOperation(self::OPERATION_RETRIEVE);
     $data = [];
     // Get store
     $store = $quote->getStoreId();
     // Get filter
     $filter = $this->getFilter();
     // Prepare methods
     foreach (Mage::helper('payment')->getStoreMethods($store, $quote) as $method) {
         /** @var $method Mage_Payment_Model_Method_Abstract */
         if ($this->_canUseMethod($method, $quote) && $method->isApplicableToQuote($quote, Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL)) {
             $method->setInfoInstance($quote->getPayment());
             $data[] = $this->prepareMethod($method, $filter);
         }
     }
     // Restore old state
     $this->setActionType($actionType);
     $this->setOperation($operation);
     // Return prepared outbound data
     return $data;
 }
Exemplo n.º 9
0
 public function checkQuoteAmount(Mage_Sales_Model_Quote $quote, $amount)
 {
     if (!$quote->getHasError() && $amount >= self::MAXIMUM_AVAILABLE_NUMBER) {
         $quote->setHasError(true);
         $quote->addMessage($this->__('Some items have quantities exceeding allowed quantities. Please select a lower quantity to checkout.'));
     }
     return $this;
 }
Exemplo n.º 10
0
 /**
  * extraxcts the according Barclaycard owner* parameter
  *
  * @param Mage_Sales_Model_Quote               $quote
  * @param Mage_Customer_Model_Address_Abstract $billingAddress
  *
  * @return array
  */
 public function getOwnerParams(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Address_Abstract $billingAddress)
 {
     $ownerParams = array();
     if ($this->getConfig()->canSubmitExtraParameter($quote->getStoreId())) {
         $ownerParams = array('OWNERADDRESS' => str_replace("\n", ' ', $billingAddress->getStreet(1)), 'OWNERTOWN' => $billingAddress->getCity(), 'OWNERZIP' => $billingAddress->getPostcode(), 'OWNERTELNO' => $billingAddress->getTelephone(), 'OWNERCTY' => $billingAddress->getCountry(), 'ECOM_BILLTO_POSTAL_POSTALCODE' => $billingAddress->getPostcode());
     }
     return $ownerParams;
 }
Exemplo n.º 11
0
 /**
  * Validates alias for in quote provided addresses
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @throws Mage_Core_Exception
  */
 protected function validateAlias($quote, $payment)
 {
     $alias = $payment->getAdditionalInformation('alias');
     if (0 < strlen(trim($alias)) && is_numeric($payment->getAdditionalInformation('cvc')) && false === Mage::helper('ops/alias')->isAliasValidForAddresses($quote->getCustomerId(), $alias, $quote->getBillingAddress(), $quote->getShippingAddress(), $quote->getStoreId())) {
         $this->getOnepage()->getCheckout()->setGotoSection('payment');
         Mage::throwException($this->getHelper()->__('Invalid payment information provided!'));
     }
 }
Exemplo n.º 12
0
 /**
  * @api
  *
  * To be used in Form_Block, which has to display all wallet types
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Payone_Core_Model_Config_Payment_Method_Interface
  */
 public function getAllConfigsByQuote(Mage_Sales_Model_Quote $quote)
 {
     if (empty($this->matchingConfigs)) {
         $configStore = $this->getConfigStore($quote->getStoreId());
         $this->matchingConfigs = $configStore->getPayment()->getMethodsForQuote($this->methodType, $quote);
     }
     return $this->matchingConfigs;
 }
Exemplo n.º 13
0
 /**
  * returns the quote currency
  *
  * @param $quote
  *
  * @return string - the quotes currency
  */
 public function getQuoteCurrency(Mage_Sales_Model_Quote $quote)
 {
     if ($quote->hasForcedCurrency()) {
         return $quote->getForcedCurrency()->getCode();
     } else {
         return Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode();
     }
 }
Exemplo n.º 14
0
 /**
  * Check if quote meets the minimun quantity
  * of total items for a specific customer
  *
  * @todo   Change to more meaningful name
  *
  * @param  Mage_Sales_Model_Quote       $quote
  * @param  Mage_Customer_Model_Customer $customer
  * @return int|false
  */
 public function minimunOrderQty(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Customer $customer)
 {
     $minQtyForCustomer = $this->getConfigValue($customer->getGroupId());
     if ($quote->getItemsQty() < $minQtyForCustomer && $quote->getItemsQty() !== 0) {
         return $minQtyForCustomer;
     }
     return false;
 }
Exemplo n.º 15
0
 /**
  * Update Quote Email Address if is guest and current email address assigned doesn't match new email
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 public function updateQuote(Mage_Sales_Model_Quote $quote)
 {
     $queue = Mage::getModel('bronto_emailcapture/queue');
     $currentEmail = $queue->getCurrentEmail();
     if (is_null($quote->getCustomerId()) && $queue->isValidEmail($currentEmail) && $quote->getCustomerEmail() !== $currentEmail) {
         $quote->setCustomerEmail(Mage::getModel('bronto_emailcapture/queue')->getCurrentEmail())->save();
     }
 }
Exemplo n.º 16
0
 /**
  * Makes Quote available for Magento Core classes
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 public function populuateQuote(Mage_Sales_Model_Quote &$quote)
 {
     $quote->save();
     $quote = Mage::getModel('sales/quote')->load($quote->getId());
     Mage::getSingleton('checkout/cart')->setQuote($quote);
     Mage::getSingleton('checkout/session')->setQuoteId($quote->getId());
     Mage::getSingleton('checkout/type_onepage')->setQuote($quote);
 }
Exemplo n.º 17
0
 /**
  * Check quote amount
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param decimal $amount
  * @return Mage_Sales_Helper_Data
  */
 public function checkQuoteAmount(Mage_Sales_Model_Quote $quote, $amount)
 {
     if (!$quote->getHasError() && $amount >= self::MAXIMUM_AVAILABLE_NUMBER) {
         $quote->setHasError(true);
         $quote->addMessage($this->__('Items maximum quantity or price do not allow checkout.'));
     }
     return $this;
 }
Exemplo n.º 18
0
 /**
  * Returns the current customers email adress.
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  * @return string the customers email adress
  */
 public function getCustomerEmail($object)
 {
     $email = $object->getCustomerEmail();
     if (empty($email)) {
         $email = $object->getBillingAddress()->getEmail();
     }
     return $email;
 }
Exemplo n.º 19
0
 /**
  * check if payment method is cc and zero amount authorization is enabled
  *
  * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
  *
  * @return bool
  */
 public function isCCAndZeroAmountAuthAllowed(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod, Mage_Sales_Model_Quote $quote)
 {
     $result = false;
     $storeId = $quote->getStoreId();
     if ($quote->getBaseGrandTotal() < 0.01 && $opsPaymentMethod instanceof Netresearch_OPS_Model_Payment_Cc && $opsPaymentMethod->isZeroAmountAuthorizationAllowed($storeId) && 0 < $quote->getItemsCount()) {
         $result = true;
     }
     return $result;
 }
Exemplo n.º 20
0
 /**
  * Declare quote model object
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Quote_Item
  */
 public function setQuote(Mage_Sales_Model_Quote $quote)
 {
     $this->_quote = $quote;
     if ($this->getHasError()) {
         $quote->setHasError(true);
     }
     $quote->addMessage($this->getQuoteMessage(), $this->getQuoteMessageIndex());
     return $this;
 }
Exemplo n.º 21
0
 /**
  * @param Mage_Sales_Model_Quote|null $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     $isAvailable = parent::isAvailable();
     $disableZeroTotal = Mage::getStoreConfig('payment/adyen_hpp/disable_zero_total', $quote->getStoreId());
     if (!is_null($quote) && $quote->getGrandTotal() <= 0 && $disableZeroTotal) {
         return false;
     }
     return $isAvailable;
 }
Exemplo n.º 22
0
 /**
  * Get QuoteItem that matches Product.
  * 
  * @param Mage_Sales_Model_Quote $quote
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Sales_Model_Quote_Item | NULL
  */
 protected function _getItemByProduct(Mage_Sales_Model_Quote $quote, Mage_Catalog_Model_Product $product)
 {
     foreach ($quote->getAllItems() as $item) {
         if ($item->getProduct()->getId() == $product->getId()) {
             return $item;
         }
     }
     return Mage::getModel("sales/quote_item")->setProduct($product)->setQuote($quote);
 }
Exemplo n.º 23
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.º 24
0
 public function callGetTaxForQuote(Mage_Sales_Model_Quote $quote)
 {
     $request = $this->createTaxRequestFromQuoteAddress($quote->getShippingAddress());
     $request = $this->prepareGetTaxRequest($request);
     $errors = $this->validateTaxRequest($request);
     if (count($errors)) {
         return $errors;
     }
     return $this->call($quote->getStore(), '1.0/tax/get', $request);
 }
Exemplo n.º 25
0
 /**
  * collect reward points that customer earned (per each item and address) total
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @param Mage_Sales_Model_Quote $quote
  * @return Magestore_RewardPoints_Model_Total_Quote_Point
  */
 public function collect($address, $quote)
 {
     if (!Mage::helper('rewardpoints')->isEnable($quote->getStoreId())) {
         return $this;
     }
     // get points that customer can earned by Rates
     if ($quote->isVirtual()) {
         $address = $quote->getBillingAddress();
     } else {
         $address = $quote->getShippingAddress();
     }
     $baseGrandTotal = $quote->getBaseGrandTotal();
     if (!Mage::getStoreConfigFlag(Magestore_RewardPoints_Helper_Calculation_Earning::XML_PATH_EARNING_BY_SHIPPING, $quote->getStoreId())) {
         $baseGrandTotal -= $address->getBaseShippingAmount();
     }
     if (!Mage::getStoreConfigFlag(Magestore_RewardPoints_Helper_Calculation_Earning::XML_PATH_EARNING_BY_TAX, $quote->getStoreId())) {
         $baseGrandTotal -= $address->getBaseTaxAmount();
     }
     $baseGrandTotal = max(0, $baseGrandTotal);
     $earningPoints = Mage::helper('rewardpoints/calculation_earning')->getRateEarningPoints($baseGrandTotal, $quote->getStoreId());
     if ($earningPoints > 0) {
         $address->setRewardpointsEarn($earningPoints);
     }
     Mage::dispatchEvent('rewardpoints_collect_earning_total_points_before', array('address' => $address));
     // Update earning point for each items
     $this->_updateEarningPoints($address);
     Mage::dispatchEvent('rewardpoints_collect_earning_total_points_after', array('address' => $address));
     return $this;
 }
Exemplo n.º 26
0
 protected function _updateQuote(Mage_Sales_Model_Quote $quote)
 {
     if (!Mage::helper('recapture')->isEnabled()) {
         return $this;
     }
     if (!$quote->getId()) {
         return;
     }
     //sales_quote_save_before gets called like 5 times on some page loads, we don't want to do 5 updates per page load
     if (Mage::registry('recapture_has_posted')) {
         return;
     }
     Mage::register('recapture_has_posted', true);
     $mediaConfig = Mage::getModel('catalog/product_media_config');
     $storeId = Mage::app()->getStore();
     $transportData = array('first_name' => $quote->getCustomerFirstname(), 'last_name' => $quote->getCustomerLastname(), 'email' => $quote->getCustomerEmail(), 'external_id' => $quote->getId(), 'grand_total' => $quote->getGrandTotal(), 'products' => array(), 'totals' => array());
     $cartItems = $quote->getAllVisibleItems();
     foreach ($cartItems as $item) {
         $productModel = $item->getProduct();
         $productImage = (string) Mage::helper('catalog/image')->init($productModel, 'thumbnail');
         //check configurable first
         if ($item->getProductType() == 'configurable') {
             if (Mage::getStoreConfig('checkout/cart/configurable_product_image') == 'itself') {
                 $child = $productModel->getIdBySku($item->getSku());
                 $image = Mage::getResourceModel('catalog/product')->getAttributeRawValue($child, 'thumbnail', $storeId);
                 if ($image) {
                     $productImage = $mediaConfig->getMediaUrl($image);
                 }
             }
         }
         //then check grouped
         if (Mage::getStoreConfig('checkout/cart/grouped_product_image') == 'parent') {
             $options = $productModel->getTypeInstance(true)->getOrderOptions($productModel);
             if (isset($options['super_product_config']) && $options['super_product_config']['product_type'] == 'grouped') {
                 $parent = $options['super_product_config']['product_id'];
                 $image = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parent, 'thumbnail', $storeId);
                 $productImage = $mediaConfig->getMediaUrl($image);
             }
         }
         $optionsHelper = Mage::helper('catalog/product_configuration');
         if ($item->getProductType() == 'configurable') {
             $visibleOptions = $optionsHelper->getConfigurableOptions($item);
         } else {
             $visibleOptions = $optionsHelper->getCustomOptions($item);
         }
         $product = array('name' => $item->getName(), 'sku' => $item->getSku(), 'price' => $item->getPrice(), 'qty' => $item->getQty(), 'image' => $productImage, 'options' => $visibleOptions);
         $transportData['products'][] = $product;
     }
     $totals = $quote->getTotals();
     foreach ($totals as $total) {
         //we pass grand total on the top level
         if ($total->getCode() == 'grand_total') {
             continue;
         }
         $total = array('name' => $total->getTitle(), 'amount' => $total->getValue());
         $transportData['totals'][] = $total;
     }
     Mage::helper('recapture/transport')->dispatch('cart', $transportData);
     return $this;
 }
Exemplo n.º 27
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  */
 protected function reactivateQuote(Mage_Sales_Model_Quote $quote)
 {
     if ($quote->getId()) {
         /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed()
          * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds
          * (Causes Integrity Constraint Violation, because orderIncrementId already exists */
         $quote->setIsActive(1)->setReservedOrderId(null)->save();
         $oSession = Mage::getSingleton('checkout/session');
         $oSession->replaceQuote($quote)->unsLastRealOrderId();
     }
 }
Exemplo n.º 28
0
 /**
  * @magentoDataFixture Mage/Sales/_files/quote.php
  * @magentoDataFixture Mage/Paypal/_files/quote_payment.php
  */
 public function testReviewAction()
 {
     $quote = new Mage_Sales_Model_Quote();
     $quote->load('test01', 'reserved_order_id');
     Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId());
     $this->dispatch('paypal/express/review');
     $html = $this->getResponse()->getBody();
     $this->assertContains('Simple Product', $html);
     $this->assertContains('Review', $html);
     $this->assertContains('/paypal/express/placeOrder/', $html);
 }
Exemplo n.º 29
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return array
  */
 protected function _buildParams($quote)
 {
     $billingAddress = $quote->getBillingAddress();
     $gender = 'female';
     if ($quote->getCustomerGender() == self::GENDER_MALE) {
         $gender = 'male';
     }
     $street = preg_split("/\\s+(?=\\S*+\$)/", $billingAddress->getStreet1());
     $params = array('gender' => $gender, 'firstname' => $billingAddress->getFirstname(), 'lastname' => $billingAddress->getLastname(), 'country' => $billingAddress->getCountry(), 'street' => $street[0], 'housenumber' => $street[1], 'zip' => $billingAddress->getPostcode(), 'city' => $billingAddress->getCity(), 'birthday' => $this->_formatDob($quote->getCustomerDob()), 'currency' => 'EUR', 'amount' => $this->_formatAmount($quote->getGrandTotal()));
     return $params;
 }
Exemplo n.º 30
0
 /**
  * Check whether payment method can be used
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     $storeId = false;
     $model = Mage::registry('current_app');
     if ($model instanceof Mage_XmlConnect_Model_Application) {
         $storeId = $model->getStoreId();
     }
     if (!$storeId) {
         $storeId = $quote ? $quote->getStoreId() : Mage::app()->getStore()->getId();
     }
     return (bool) Mage::getModel('paypal/config')->setStoreId($storeId)->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
 }