/** * Truncate the customer's cart if active * @access public * @return void */ public function truncateCustomerCart(Varien_Event_Observer $observer) { if (Mage::helper('jbh_cartmerge')->isActive()) { if ($observer->getSource()->hasItems() || Mage::helper('jbh_cartmerge')->cleanIfEmpty()) { if (is_object($observer->getQuote()) && $observer->getQuote()->getId()) { $observer->getQuote()->removeAllItems(); } } } }
public function newstoreMemberCheck(Varien_Event_Observer $observer) { if (Mage::getSingleton('customer/session')->isLoggedIn()) { $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId(); if (Mage::helper('ism_newstore_members')->isMemberValid($customerId)) { $customer = Mage::getModel('ism_newstore_members/members')->load($customerId, 'customer_id'); if (Mage::helper('ism_newstore_members')->isMemberAddress($customerId)) { $observer->getQuote()->setNewstoreMemberCode($customer->getUniqueKey()); return; } } } $observer->getQuote()->setNewstoreMemberCode(null); }
/** * On quote save during admin order creation, if guess address was populated in this request, * set a flag on the session * * @param Varien_Event_Observer $observer */ public function adminQuoteFlagGuestAddress(Varien_Event_Observer $observer) { $quote = $observer->getQuote(); if ($quote->getFlagGuestAddressOnSave()) { Mage::getSingleton('adminhtml/session_quote')->setIsGuestAddressPopulated(true); } }
/** * @param Varien_Event_Observer $observer * @event sales_quote_merge_before */ public function observe(Varien_Event_Observer $observer) { /** @var Aleron75_UnmergedCart_Helper_Data $h */ $h = Mage::helper('aleron75_unmergedcart'); if (!$h->isActive()) { return; } /** @var Mage_Sales_Model_Quote $customerQuote */ $customerQuote = $observer->getQuote(); /** @var Mage_Sales_Model_Quote $sessionQuote */ $sessionQuote = $observer->getSource(); if ($customerQuote->getId() && $sessionQuote->getId() != $customerQuote->getId()) { /** @var Mage_Sales_Model_Quote $discardableQuote */ $discardableQuote = $h->isKeepSessionCart() ? $customerQuote : $sessionQuote; /** @var Mage_Sales_Model_Quote_Item $item */ foreach ($discardableQuote->getAllItems() as $item) { $item->isDeleted(true); if ($item->getHasChildren()) { /** @var Mage_Sales_Model_Quote_Item_Abstract $child */ foreach ($item->getChildren() as $child) { $child->isDeleted(true); } } } } }
public function sales_model_service_quote_submit_after(Varien_Event_Observer $observer) { $method = $observer->getEvent()->getOrder()->getPayment()->getMethod(); // Only non-gateway methods if ($method === 'bitcoin') { $observer->getQuote()->setIsActive(true); } }
/** * Deactivates quote after succeed order placement, this is temporary solution for correct CRM processing * * @param Varien_Event_Observer $observer */ public function onSubmitAllAfter(Varien_Event_Observer $observer) { /** @var Mage_Sales_Model_Quote $quote */ $quote = $observer->getQuote(); if (Mage::helper('oro_api')->isOroRequest() && (bool) $quote->getOrigData('is_active')) { $quote->setIsActive(false)->save(); } }
/** * When load() function is called on the quote object, * we read our custom fields value from database and put them back in quote object. * * @param Varien_Event_Observer $oObserver */ public function salesQuoteLoadAfter(Varien_Event_Observer $oObserver) { if ($this->isExtensionActive()) { $oQuote = $oObserver->getQuote(); /** @var Sitewards_DeliveryDate_Model_Quote $oModel */ $oModel = Mage::getModel('sitewards_deliverydate/quote'); $this->addInformationToObject($oQuote, $oModel); } }
public function sales_model_service_quote_submit_after(Varien_Event_Observer $observer) { $method = $observer->getEvent()->getOrder()->getPayment()->getMethod(); if (substr($method, 0, 6) == 'sisow_') { if (Mage::getStoreConfig('sisow_core/keepcart')) { $observer->getQuote()->setIsActive(TRUE); } } }
public function updateQuote(Varien_Event_Observer $observer) { $quote = $observer->getQuote(); if ($quote instanceof Mage_Sales_Model_Quote) { $countryId = $quote->getBillingAddress()->getCountryId(); if (empty($countryId)) { $quote->getBillingAddress()->setCountryId(Mage::helper('aitcheckout')->getDefaultCountry()); } } }
/** * @param string $filterClass * @param Varien_Event_Observer $observer * @return void */ protected function _addFilter($filterClass, Varien_Event_Observer $observer) { $quote = $observer->getQuote(); $result = $observer->getResult(); // stdClass with property "isAvailable" $paymentMethodInstance = $observer->getMethodInstance(); /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */ $customerGroupFilter = Mage::getModel($filterClass); $customerGroupFilter->setResult($result); $customerGroupFilter->setMethodInstance($paymentMethodInstance); $customerGroupFilter->setQuote($quote); $customerGroupFilter->filter(); }
public function salesModelServiceQuoteSubmitAfter(Varien_Event_Observer $observer) { $order = $observer->getOrder(); $quote = $observer->getQuote(); $paymentMethod = $quote->getPayment(); if ($paymentMethod->getMethod() == 'creditcard' && $quote->getPayment()->getOrderPlaceRedirectUrl()) { $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT; $order->setState($state); $order->setStatus('pending_payment'); $order->setIsNotified(false); $order->save(); } }
function onSalesOrderPlaceBefore(Varien_Event_Observer $observer) { $customer = $observer->getOrder()->getCustomer(); $password = $customer->getPassword(); $quote = $observer->getQuote(); $checkoutMethod = $quote->getData('checkout_method'); if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER || $checkoutMethod == 'register') { // Magento does not create a customer account during checkout via PayPal prior to v 1.6.1 // thus in that case we should disable the following check to prevent unnecessary error if (!(version_compare(Mage::getVersion(), '1.6.1', 'lt') && $quote->getPayment()->getMethod() == Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS && !$customer->getEmail())) { if (!$password === NULL || $password == '') { Mage::throwException(Mage::helper('aitcheckout')->__('The password cannot be empty.')); } } } }
/** * Called on sales_quote_collect_totals_after. Ensure that the action is couponPost before continuing. * * @param Varien_Event_Observer $observer */ public function validateCode(Varien_Event_Observer $observer) { $action = Mage::app()->getRequest()->getActionName(); if ($action == 'couponPost') { if (Mage::app()->getRequest()->getParam('remove') == 1) { return; } $quote = $observer->getQuote(); $couponCode = $quote->getCouponCode(); if (!$couponCode || $couponCode == '') { // parent validation has failed $couponCode = (string) Mage::app()->getRequest()->getParam('coupon_code'); $msg = Mage::getModel('hackathon_promocodemessages/validator')->validate($couponCode); Mage::throwException($msg); } } }
/** * preload price rules * * @param Varien_Event_Observer $observer Observer * * @return void */ public function preloadPriceRules(Varien_Event_Observer $observer) { $quote = $observer->getQuote(); $date = Mage::app()->getLocale()->storeTimeStamp($quote->getStoreId()); $websiteId = $quote->getStore()->getWebsiteId(); $groupId = $quote->getCustomerGroupId(); $productIds = array(); foreach ($quote->getAllItems() as $item) { $productIds[] = $item->getProductId(); } $cacheKey = spl_object_hash($quote); if (!isset($this->_preloadedPrices[$cacheKey])) { $this->_preloadedPrices[$cacheKey] = Mage::getResourceSingleton('catalogrule/rule')->getRulePrices($date, $websiteId, $groupId, $productIds); } foreach ($this->_preloadedPrices[$cacheKey] as $productId => $price) { $key = implode('|', array($date, $websiteId, $groupId, $productId)); $this->_rulePrices[$key] = $price; } }
/** * Update rate price in the checkout * * TIG_MyParcel2014_Helper_Data::updateRatePrice() also ensures that the price will be adjusted at checkout * * @param Varien_Event_Observer $observer * * @return $this */ public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer) { /** @var TIG_MyParcel2014_Helper_Data $helper */ $helper = Mage::helper('tig_myparcel'); /** * @var Mage_Sales_Model_Quote $quote */ $quote = $observer->getQuote(); $price = Mage::getSingleton('core/session')->getMyParcelBasePrice(); $shipAddress = $quote->getShippingAddress(); if ($price === null) { foreach ($shipAddress->getShippingRatesCollection() as $rate) { if ($rate->getCarrier() == 'myparcel') { $price = $rate->getPrice(); Mage::getSingleton('core/session')->setMyParcelBasePrice($price); } } } if (strpos($shipAddress->getShippingMethod(), 'myparcel') !== false) { $helper->calculatePrice($price); } }
/** * This event should only fire on the "frontend". It reads Bronto's * "tid" cookie value and assigns to the shopping cart. * * @param Varien_Event_Observer $observer */ public function addTidToQuote(Varien_Event_Observer $observer) { /* @var $quote Mage_Sales_Model_Quote */ $quote = $observer->getQuote(); /* @var $contactQueue Bronto_Order_Model_Queue */ $orderRow = Mage::getModel('bronto_order/queue')->getOrderRow(null, $quote->getId(), $quote->getStoreId()); // Somehow we got a situation where an order was placed on this entry if ($orderRow->getOrderId() && !is_null($orderRow->getBrontoTid())) { return; } $tid = Mage::helper('bronto_order')->getTidKey(); foreach (Mage::getModel('core/cookie')->get() as $key => $value) { if ('tid_' . $tid == $key) { try { $orderRow->setBrontoTid($value)->save(); } catch (Exception $e) { Mage::helper('bronto_order')->writeError("Failed to save tid on a quote: " . $e->getMessage()); } break; } } }
public function paymentMethodIsActive(Varien_Event_Observer $observer) { if (!$this->_helper->isActive()) { return; } $event = $observer->getEvent(); $method = $event->getMethodInstance(); $result = $event->getResult(); $paymentMethod = $method->getCode(); $quote = $observer->getQuote(); if (is_object($quote)) { $address = $quote->getShippingAddress(); } else { return; } $shippingMethod = $address->getShippingMethod(); if ($shippingMethod && $shippingMethod != 'milkman_deliveries_standard' && strpos($shippingMethod, "milkman_deliveries") !== false) { $disablePaymentMethods = Mage::getStoreConfig('carriers/milkman_deliveries/disable_payment_methods'); $disablePaymentMethods = explode(',', $disablePaymentMethods); if (in_array($paymentMethod, $disablePaymentMethods)) { $result->isAvailable = false; $this->_helper->log("paymentMethodIsActive: payment method {$paymentMethod} disabled "); } } }
/** * Event fired when setting shipping price on checkout after address is saved * @param Varien_Event_Observer $observer */ public function setShippingCostOnExtend(Varien_Event_Observer $observer) { $quote = $observer->getQuote(); // Check your customer attribute of choice here instead of the customer id if (Mage::getSingleton('checkout/session')->getIsExtendedQuote() || Mage::getSingleton('adminhtml/session_quote')->getIsExtendedQuote()) { $store = Mage::app()->getStore($quote->getStoreId()); $carriers = Mage::getStoreConfig('carriers', $store); foreach ($carriers as $carrierCode => $carrierConfig) { // F for fixed, P for percentage $store->setConfig("carriers/{$carrierCode}/price", '0'); } } }
public function deliveryAtToQuote(Varien_Event_Observer $observer) { $observer->getQuote()->setDeliveryAt($observer->getRequest()->getPost('delivery_at')); }
public function updateSalesQuotePayment(Varien_Event_Observer $observer) { try { if (!is_null($observer->getQuote())) { $params = Mage::app()->getFrontController()->getRequest()->getParams(); $params['installments_bcash'] = isset($params['installments_bcash']) ? $params['installments_bcash'] : 1; } } catch (Exception $e) { Mage::helper("bcash")->saveLog("Exception- Model_Observer->updateSalesQuotePayment: " . $e->getMessage()); } }
/** * Do not allow guest checkout when adyen subscription item is added * @param Varien_Event_Observer $observer */ public function isAllowedGuestCheckout(Varien_Event_Observer $observer) { if (Mage::helper('core')->isModuleEnabled('Ho_Customer') && Mage::helper('ho_customer')->autoCreateCustomers()) { return; } /** @noinspection PhpUndefinedMethodInspection */ /** @var Mage_Sales_Model_Quote $quote */ $quote = $observer->getQuote(); /** @noinspection PhpUndefinedMethodInspection */ /** @var Varien_Object $result */ $result = $observer->getResult(); Mage::getSingleton('adyen_subscription/product_observer')->isQuoteAdyenSubscription($quote); if ($quote->getData('_is_adyen_subscription')) { /** @noinspection PhpUndefinedMethodInspection */ $result->setIsAllowed(false); } }
/** * @param Varien_Event_Observer $observer * @return ICC_Ecodes_Model_Observer */ public function isAllowedGuestCheckout(Varien_Event_Observer $observer) { $quote = $observer->getQuote(); $result = $observer->getResult(); if ($quote instanceof Mage_Sales_Model_Quote) { if ($this->_hasEcodeItems($quote)) { $result->setIsAllowed(false); } } return $this; }
/** * @event payment_method_is_active * @param Varien_Event_Observer $observer * @return $this */ public function isPaymentMethodActive(Varien_Event_Observer $observer) { /** @var Mage_Sales_Model_Quote $quote */ /** @noinspection PhpUndefinedMethodInspection */ $quote = $observer->getQuote(); if (!$quote) { return $this; } if (!$this->isQuoteAdyenSubscription($quote)) { return $this; } /** @var Mage_Payment_Model_Method_Abstract $methodInstance */ /** @noinspection PhpUndefinedMethodInspection */ $methodInstance = $observer->getMethodInstance(); $methodInstance->setMode('subscription'); /** * The method canCreateContractTypeRecurring returns true for: * Inital Payments: checks for setting in Admin Panel: payment/adyen_abstract/recurringtypes * if RECURRING or ONECLICK,RECURRING is set * Stored cards/sepa: checks recurring_type in BA agreement_data. * if RECURRING or ONECLICK,RECURRING is set * * For instances that allow ONECLICK (ONECLICK,RECURRING) we need to set the mode to RECURRING. */ // You need to do a recurring transaction for subscriptions if (method_exists($methodInstance, 'setCustomerInteraction')) { /** @var $methodInstance Adyen_Payment_Model_Adyen_Oneclick */ $methodInstance->setCustomerInteraction(false); } // check if payment method is selected in config $selectedSubscriptionPaymentMethods = Mage::helper('adyen_subscription/config')->getSelectedSubscriptionPaymentMethods(); // check if payment method is in the key $code = $methodInstance->getCode(); // Set method to unavailable and check below if it is possible to use $observer->getResult()->isAvailable = false; /* * Check if payment method is in selectedPaymentMethods and * validate if payment method is available for Adyen subscription */ if (array_key_exists($code, $selectedSubscriptionPaymentMethods) && method_exists($methodInstance, 'canCreateAdyenSubscription') && $methodInstance->canCreateAdyenSubscription()) { $observer->getResult()->isAvailable = true; } //@todo move paymen specific logic to Adyen_Payments module, this causes tight coupling. // restrict MAESTRO payment method for creditcards because MEASTRO does not support Recurring if ($code == "adyen_cc") { $types = $methodInstance->getAvailableCCTypes(); if (isset($types['SM'])) { unset($types['SM']); $methodInstance->setAvailableCCypes($types); } } /* * For ONECLCIK payment check if it is allowed by selectedPaymentMethods configuration */ if ($code != "adyen_oneclick" && strpos($code, 'adyen_oneclick') !== false) { $recurringDetails = $methodInstance->getRecurringDetails(); if (isset($recurringDetails['variant'])) { //@todo move the available credit cards to the config, one location where all the credit cards are specified $creditcards = array('visa', 'mc', 'amex', 'discover', 'diners', 'maestro', 'jcb', 'elo', 'Hipercard'); if (in_array($recurringDetails['variant'], $creditcards) && isset($selectedSubscriptionPaymentMethods['adyen_cc'])) { $observer->getResult()->isAvailable = true; } elseif ($recurringDetails['variant'] == "sepadirectdebit" && isset($selectedSubscriptionPaymentMethods['adyen_sepa'])) { $observer->getResult()->isAvailable = true; } elseif ($recurringDetails['variant'] == "paypal" && isset($selectedSubscriptionPaymentMethods['adyen_hpp_paypal'])) { $observer->getResult()->isAvailable = true; } elseif ($recurringDetails['variant'] == "directEbanking" && isset($selectedSubscriptionPaymentMethods['adyen_hpp_directEbanking'])) { $observer->getResult()->isAvailable = true; } } } if (Mage::app()->getRequest()->getParam('subscription')) { if (!method_exists($methodInstance, 'isBillingAgreement') || !$methodInstance->isBillingAgreement()) { $observer->getResult()->isAvailable = false; } } return $this; }
/** * Revert emulated customer group_id * * @param Varien_Event_Observer $observer */ public function quoteSubmitAfter($observer) { /** @var $customer Mage_Customer_Model_Customer */ $customer = $observer->getQuote()->getCustomer(); if (!Mage::helper('customer/address')->isVatValidationEnabled($customer->getStore())) { return; } if (!$customer->getId()) { return; } $customer->setGroupId($customer->getOrigData('group_id')); $customer->save(); }
/** * Sets card cookie * * @param Varien_Event_Observer $observer */ public function setCardCookie($observer) { $quoteData = $observer->getQuote()->debug(); unset($quoteData['updated_at']); $this->setCookies(array(self::COOKIE_CART => $this->_hashData($quoteData), self::COOKIE_SEGMENT => $this->_hashData($this->_getHelper()->getCustomerSegment()))); }
public static function salesQuoteSaveAfter(Varien_Event_Observer $observer) { Mage::helper('ewpagecache')->log(sprintf('Running salesQuoteSaveAfter()')); if (Mage::helper('ewpagecache/config')->isPrimaryCacheReentryEnabled() === true) { $quote = $observer->getQuote(); if ($quote->getItemsCount() > 0) { Mage::helper('ewpagecache')->setIsNotDefaultRequestReason(true, 'cart'); } else { Mage::helper('ewpagecache')->setIsNotDefaultRequestReason(false, 'cart'); Mage::helper('ewpagecache')->setIsNotDefaultRequestReason(false, 'post'); } } else { Mage::helper('ewpagecache')->setIsNotDefaultRequestReason(true, 'cart'); } }
/** * Export quote discounts info to order * @param Varien_Event_Observer $observer */ public function salesConvertQuoteToOrder($observer) { $observer->getOrder()->setAuctaneapiDiscounts($observer->getQuote()->getAuctaneapiDiscounts()); }
/** * */ public function collectParentItemProducts(Varien_Event_Observer $observer) { if (Mage::helper('ddq')->isEnabled()) { // array of requested items (grouped products for example adds several items at the same time) $items = $observer->getQuote() ? $observer->getQuote()->getItemsCollection() : array(); if (count($items)) { foreach ($items as $item) { if ($item->getParentItem()) { $this->_getHelper()->addActiveItemParentProduct($item); } } } } }