Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * Get all quote totals
  *
  * We need to remove a sisow_tax line that is created from
  * one of our models. Otherwise there will be two tax lines in the
  * checkout
  *
  * @return array
  */
 public function getTotals()
 {
     $totals = parent::getTotals();
     unset($totals['sisow_tax']);
     $totalsIndex = array_keys($totals);
     if (array_search('sisow_fee', $totalsIndex) === false) {
         return $totals;
     }
     unset($totalsIndex[array_search('sisow_fee', $totalsIndex)]);
     $fee = $totals['sisow_fee'];
     unset($totals['sisow_fee']);
     $feeIndex = array_search('shipping', $totalsIndex);
     if ($feeIndex === false) {
         $feeIndex = array_search('subtotal', $totalsIndex) + 1;
     }
     $sortedTotals = array();
     $size = count($totalsIndex);
     for ($i = 0; $i < $size; $i++) {
         if ($i == $feeIndex) {
             $sortedTotals['sisow_fee'] = $fee;
         }
         $sortedTotals[array_shift($totalsIndex)] = array_shift($totals);
     }
     return $sortedTotals;
 }
 /**
  * Get the specified total amount for the quote.
  *
  * @param  string
  * @param  Mage_Sales_Model_Quote
  * @return float
  */
 protected function getTotal($type, Mage_Sales_Model_Quote $quote)
 {
     $totals = $quote->getTotals();
     return isset($totals[$type]) ? $totals[$type]->getValue() : 0.0;
 }
Ejemplo n.º 4
0
 /**
  * @param \Vbw\Procurement\Punchout\Order $poOrder
  * @param Mage_Sales_Model_Quote $quote
  */
 public function addTotal($poOrder, $quote)
 {
     $configHelper = Mage::helper('vbw_punchout/config');
     /**@var $dataHelper Vbw_Punchout_Helper_Data*/
     $dataHelper = Mage::helper('vbw_punchout/data');
     /** @var $body \Vbw\Procurement\Punchout\Order\Body */
     $body = $poOrder->getBody();
     $totals = $quote->getTotals();
     $total = $quote->getSubtotal();
     if ($configHelper->getconfig('order/include_discount')) {
         if (isset($totals['discount'])) {
             $shippingTotal = $totals['discount']->getValue();
             $total += $shippingTotal;
         }
     }
     if ($configHelper->getconfig('order/include_shipping')) {
         if (isset($totals['shipping'])) {
             $shippingTotal = $totals['shipping']->getValue();
             $total += $shippingTotal;
         }
     }
     if ($configHelper->getconfig('order/include_tax')) {
         if (isset($totals['tax'])) {
             $taxTotal = $totals['tax']->getValue();
             $total += $taxTotal;
         }
     }
     $body->setTotal($dataHelper->getAsStoreCurrency($total));
 }
Ejemplo n.º 5
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return Bronto_Common_Model_Email_Template_Filter
  */
 protected function _filterQuote(Mage_Sales_Model_Quote $quote)
 {
     if (!in_array('quote', $this->_filteredObjects)) {
         $this->setStoreId($quote->getStoreId());
         $currencyCode = $quote->getQuoteCurrencyCode();
         if (Mage::helper('bronto_common')->displayPriceIncTax($quote->getStoreId())) {
             $totals = $quote->getTotals();
             $this->setField('subtotal', $this->formatPrice($totals['subtotal']->getValue(), $currencyCode));
             $this->setField('grandTotal', $this->formatPrice($totals['grand_total']->getValue(), $currencyCode));
         } else {
             $this->setField('subtotal', $this->formatPrice($quote->getSubtotal(), $currencyCode));
             $this->setField('grandTotal', $this->formatPrice($quote->getGrandTotal(), $currencyCode));
         }
         $index = 1;
         foreach ($quote->getAllItems() as $item) {
             if (!$item->getParentItem()) {
                 $this->_filterQuoteItem($item, $index);
                 $index++;
             }
         }
         // Add Related Content
         $this->_items = $quote->getAllItems();
         $queryParams = $this->getQueryParams();
         $queryParams['id'] = urlencode(base64_encode(Mage::helper('core')->encrypt($quote->getId())));
         if ($store = $this->getStore()) {
             $this->setField('quoteURL', $store->getUrl('reminder/load/index', $queryParams));
         } else {
             $this->setField('quoteURL', Mage::getUrl('reminder/load/index', $queryParams));
         }
         // Setup quote items as a template
         if (class_exists('Bronto_Reminder_Block_Cart_Items', false)) {
             $layout = Mage::getSingleton('core/layout');
             /* @var $items Mage_Sales_Block_Items_Abstract */
             $items = $layout->createBlock('bronto/bronto_reminder_cart_items', 'items');
             $items->setTemplate('bronto/reminder/items.phtml');
             $items->setQuote($item->getQuote());
             $this->_respectDesignTheme();
             $this->setField("cartItems", $items->toHtml());
         }
         $this->_filteredObjects[] = 'quote';
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Build Amount
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Amount
  */
 protected function buildAmount($quote)
 {
     $details = new Details();
     $details->setShipping($quote->getShippingAddress()->getBaseShippingAmount())->setTax($quote->getBillingAddress()->getBaseTaxAmount() + $quote->getBillingAddress()->getBaseHiddenTaxAmount() + $quote->getShippingAddress()->getBaseTaxAmount() + $quote->getShippingAddress()->getBaseHiddenTaxAmount())->setSubtotal($quote->getBaseSubtotal());
     $totals = $quote->getTotals();
     if (isset($totals['discount']) && $totals['discount']->getValue()) {
         $details->setShippingDiscount(-$totals['discount']->getValue());
     }
     $amount = new Amount();
     $amount->setCurrency($quote->getBaseCurrencyCode())->setDetails($details)->setTotal($quote->getBaseGrandTotal());
     return $amount;
 }