/** * Calculate discounts by sales rules * @param Varien_Event_Observer $observer */ public function salesruleProcess($observer) { $quote = $observer->getQuote(); $address = $observer->getAddress(); $rule = $observer->getRule(); $discounts = @unserialize($quote->getAuctaneapiDiscounts()); if (!self::$_counter) { $discounts = array(); $address->setBaseShippingDiscountAmount(0); self::$_counter++; } if (!isset(self::$_shippingAmountProcessed[$rule->getId()]) && $address->getShippingAmount()) { $shippingAmount = $address->getShippingAmountForDiscount(); if ($shippingAmount !== null) { $baseShippingAmount = $address->getBaseShippingAmountForDiscount(); } else { $baseShippingAmount = $address->getBaseShippingAmount(); } //check for discount applied on shipping amount or not if (!$rule['apply_to_shipping']) { $baseShippingAmount = 0; } $baseDiscountAmount = 0; $rulePercent = min(100, $rule->getDiscountAmount()); switch ($rule->getSimpleAction()) { case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION: $rulePercent = max(0, 100 - $rule->getDiscountAmount()); case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION: $baseDiscountAmount = ($baseShippingAmount - $address->getBaseShippingDiscountAmount()) * $rulePercent / 100; break; case Mage_SalesRule_Model_Rule::TO_FIXED_ACTION: $baseDiscountAmount = $baseShippingAmount - $rule->getDiscountAmount(); break; case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION: $baseDiscountAmount = $rule->getDiscountAmount(); break; case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION: self::$_cartRules = $address->getCartFixedRules(); if (!isset(self::$_cartRules[$rule->getId()])) { self::$_cartRules[$rule->getId()] = $rule->getDiscountAmount(); } if (self::$_cartRules[$rule->getId()] > 0) { $baseDiscountAmount = min($baseShippingAmount - $address->getBaseShippingDiscountAmount(), self::$_cartRules[$rule->getId()]); self::$_cartRules[$rule->getId()] -= $baseDiscountAmount; } break; } $ruleDiscount = 0; $left = $baseShippingAmount - ($address->getBaseShippingDiscountAmount() + $baseDiscountAmount); if ($left >= 0) { $ruleDiscount = $baseDiscountAmount; } $discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount() + $ruleDiscount; $address->setBaseShippingDiscountAmount(min($address->getBaseShippingDiscountAmount() + $baseDiscountAmount, $baseShippingAmount)); self::$_shippingAmountProcessed[$rule->getId()] = true; } else { $discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount(); } $quote->setAuctaneapiDiscounts(@serialize($discounts)); }
/** * Check if customer group can use the payment method * * @param Varien_Event_Observer $observer * @return bool */ public function methodIsAvailable(Varien_Event_Observer $observer) { $paymentMethodInstance = $observer->getMethodInstance(); /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */ $result = $observer->getResult(); $customer = Mage::helper('customer')->getCustomer(); /* @var $customer Mage_Customer_Model_Customer */ if ($paymentMethodInstance instanceof Mage_Paypal_Model_Standard) { $customerGroupConfig = Mage::getStoreConfig('paypal/wps/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } elseif ($paymentMethodInstance instanceof Mage_Paypal_Model_Express) { $customerGroupConfig = Mage::getStoreConfig('paypal/express/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } elseif ($paymentMethodInstance instanceof Mage_GoogleCheckout_Model_Payment) { $customerGroupConfig = Mage::getStoreConfig('google/checkout/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } else { $customerGroupConfig = $paymentMethodInstance->getConfigData(self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } if (!empty($customerGroupConfig)) { $methodCustomerGroups = explode(',', $customerGroupConfig); if (count($methodCustomerGroups) > 0) { if (!in_array($customer->getGroupId(), $methodCustomerGroups)) { $result->isAvailable = false; } } } return true; }
/** * Check if customer group can use the payment method * * @param Varien_Event_Observer $observer * @return bool */ public function methodIsAvailable(Varien_Event_Observer $observer) { /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */ $paymentMethodInstance = $observer->getMethodInstance(); /* @var $customer Mage_Customer_Model_Customer */ if (Mage::app()->getStore()->isAdmin()) { $customer = Mage::getSingleton('adminhtml/session_quote')->getCustomer(); } else { $customer = Mage::getSingleton('customer/session')->getCustomer(); } if ($paymentMethodInstance instanceof Mage_Paypal_Model_Standard) { $customerGroupConfig = Mage::getStoreConfig('paypal/wps/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } elseif ($paymentMethodInstance instanceof Mage_Paypal_Model_Express) { $customerGroupConfig = Mage::getStoreConfig('paypal/express/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } elseif ($paymentMethodInstance instanceof Mage_GoogleCheckout_Model_Payment) { // VK: this won't work $customerGroupConfig = Mage::getStoreConfig('google/checkout/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } else { $customerGroupConfig = $paymentMethodInstance->getConfigData(self::XML_CUSTOMER_GROUP_CONFIG_FIELD); } if ($customerGroupConfig) { $customerGroupsAllowed = explode(',', $customerGroupConfig); $observer->getResult()->isAvailable = in_array($customer->getGroupId(), $customerGroupsAllowed); } }
public function disallowRegistration(Varien_Event_Observer $observer) { //Mage::dispatchEvent('admin_session_user_login_success', array('user'=>$user)); //$user = $observer->getEvent()->getUser(); //$user->doSomething(); $observer->getResult()->setIsAllowed(false); }
/** * Called from payperrentals/inventory helper after_booked event of getBooked() * * Observer that adds maintenance quantity when using specific maintenance dates to * the serialized inventory field of the product * * @param Varien_Event_Observer $observer */ function addMaintenanceToSerialized(Varien_Event_Observer $observer) { $booked = $observer->getResult()->getBooked(); $reservedCollection = $observer->getReservedCollection(); /** @var $maintenanceColl ITwebexperts_Maintenance_Model_Mysql4_Items_Collection */ foreach ($booked as $productid => $booking) { $maintenanceColl = Mage::getModel('simaintenance/items')->getCollection(); $maintenanceColl->addFieldToFilter('product_id', $productid); foreach ($maintenanceColl as $maintenanceItem) { if (is_null($maintenanceItem->getStartDate()) || $maintenanceItem->getSpecificDates()) { continue; } $start = strtotime($maintenanceItem->getStartDate()); $end = strtotime($maintenanceItem->getEndDate()); $usetimes = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productid, 'payperrentals_use_times', Mage::app()->getStore()->getStoreId()); if (date('H:i:s', $start) != '00:00:00' || date('H:i:s', $end) != '23:59:00' && date('H:i:s', $end) != '23:58:59' || $usetimes == 1) { $configHelper = Mage::helper('payperrentals/config'); $timeIncrement = $configHelper->getTimeIncrement() * 60; } else { $timeIncrement = 3600 * 24; } while ($start < $end) { $dateFormatted = date('Y-m-d H:i', $start); if (!isset($booking[$dateFormatted])) { $vObject = new Varien_Object(); $vObject->setQty($maintenanceItem->getQuantity()); $vObject->setOrders(array('m')); $booking[$dateFormatted] = $vObject; } else { $vObject = $booking[$dateFormatted]; $vObject->setQty($vObject->getQty() + $maintenanceItem->getQuantity()); $orderArr = $vObject->getOrders(); $orderArr = array_merge($orderArr, array('m')); $vObject->setOrders($orderArr); } $booked[$productid][$dateFormatted] = $vObject; $start += $timeIncrement; } } } $observer->getResult()->setBooked($booked); }
public function disableMethod(Varien_Event_Observer $observer) { $moduleName = "Raveinfosys_Linkpoint"; if ('linkpoint' == $observer->getMethodInstance()->getCode()) { if (!Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) { //nothing here, as module is ENABLE } else { $observer->getResult()->isAvailable = false; } } }
/** * @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(); }
/** * Enable Payement Methods as per the the * store config * * @param Varien_Event_Observer $observer * @return void */ public function enablePayementMethods(Varien_Event_Observer $observer) { $methodInstance = $observer->getEvent(); $paymentMethod = $methodInstance->getMethodInstance(); $config = Mage::getStoreConfig('adminpayments/general/active', $paymentMethod->getStore()); if (!$config) { return; } $result = $observer->getResult(); $adminPayments = explode(',', $config); if (in_array($paymentMethod->getCode(), $adminPayments) && false == $result->isAvailable) { $result->isAvailable = true; } }
/** * Check if customer group can use the payment method * * @param Varien_Event_Observer $observer * @return bool */ public function methodIsAvailable(Varien_Event_Observer $observer) { if (Mage::getStoreConfigFlag(self::PAYMENT_SSO_ACTIVE) && Mage::getSingleton('customer/session')->isLoggedIn()) { $paymentMethodInstance = $observer->getMethodInstance(); /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */ $result = $observer->getResult(); $targetGroup = Mage::getModel('customer/group'); $targetGroup->load(Mage::getSingleton('customer/session')->getCustomerGroupId()); if ($paymentMethodInstance->getCode() != 'wallet' && $targetGroup->getData('customer_group_code') == 'Stelo') { $result->isAvailable = false; } return true; } }
/** * Add the invoice comments * * @param Varien_Event_Observer $observer observer object * * @return FireGento_Pdf_Model_Observer */ public function addInvoiceComments(Varien_Event_Observer $observer) { if (!Mage::getStoreConfigFlag('sales_pdf/invoice/show_comments')) { return $this; } /** @var Mage_Sales_Model_Order_Invoice $invoice */ $invoice = $observer->getInvoice(); /** @var Mage_Sales_Model_Resource_Order_Invoice_Comment_Collection $commentsCollection */ $commentsCollection = $invoice->getCommentsCollection(); $commentsCollection->addVisibleOnFrontFilter(); $result = $observer->getResult(); $notes = $result->getNotes(); foreach ($commentsCollection as $comment) { /** @var $comment Mage_Sales_Model_Order_Invoice_Comment */ $notes[] = $comment->getComment(); } $result->setNotes($notes); 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; }
/** * Add shipping method to invoice notes. * * @param Varien_Event_Observer $observer * @return FireGento_Pdf_Model_Observer */ public function addShippingMethod(Varien_Event_Observer $observer) { if (Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') != FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_NOTE) { return $this; } $result = $observer->getResult(); $notes = $result->getNotes(); $notes[] = Mage::helper('firegento_pdf')->__('Shipping method: %s', $observer->getOrder()->getShippingDescription()); $result->setNotes($notes); return $this; }
/** * @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; }
/** * 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); } }
public function saveCart(Varien_Event_Observer $observer) { /** @var VladimirPopov_WebForms_Model_Results $result */ $result = $observer->getResult(); /** @var VladimirPopov_WebForms_Model_Webforms $webform */ $form = $result->getWebform(); $postData = $result->getData('field'); // detect that the form should operate with cart if (strstr($form->getCode(), "f2c")) { /* * products array to be added to the cart */ $products = array(); /* * field code naming conventions * f2c-product-id-<product id> * f2c-product-<product id>-option-<option sku> * f2c-product-<product id>-quantity */ // collect product ids foreach ($form->getFieldsToFieldsets(true) as $fieldset) { /** @var VladimirPopov_WebForms_Model_Fields $field */ foreach ($fieldset["fields"] as $field) { if (strstr($field->getCode(), "f2c-product-id")) { $product_id = trim(str_replace("f2c-product-id-", "", $field->getCode())); if ($product_id && !in_array($product_id, $products)) { $products[$product_id] = array("qty" => 1, "product" => $product_id); } } } } // collect custom options and quantities foreach ($form->getFieldsToFieldsets(true) as $fieldset) { /** @var VladimirPopov_WebForms_Model_Fields $field */ foreach ($products as $product_id => $data) { $product = Mage::getModel('catalog/product')->load($product_id); foreach ($fieldset["fields"] as $field) { // collect product custom options if (count($product->getOptions()) > 0) { if (strstr($field->getCode(), "f2c-product-{$product_id}-option-")) { $option_sku = trim(str_replace("f2c-product-{$product_id}-option-", "", $field->getCode())); $option_value = $postData[$field->getId()]; foreach ($product->getOptions() as $opt) { // find match with option sku if ($opt->getSku() == $option_sku) { if (in_array($field->getType(), array('file', 'image'))) { $fullpath = $result->getFileFullPath($field->getId(), $postData[$field->getId()]); $quote_path = DS . 'media' . DS . $result->getRelativePath($field->getId(), $postData[$field->getId()]); $imgSize = getimagesize($fullpath); $products[$product_id]["options"][$opt->getId()] = array("type" => $_FILES["file_" . $field->getId()]["type"], "size" => $_FILES["file_" . $field->getId()]["size"], "width" => $imgSize[0], "height" => $imgSize[1], "quote_path" => $quote_path, "order_path" => $quote_path, "fullpath" => $fullpath, "title" => $postData[$field->getId()], 'secret_key' => substr(md5(file_get_contents($fullpath)), 0, 20)); } else { $products[$product_id]["options"][$opt->getId()] = $option_value; } } } } } // collect quantity if (strstr($field->getCode(), "f2c-product-{$product_id}-quantity")) { $quantity = intval($postData[$field->getId()]); if ($quantity > 0) { $products[$product_id]["qty"] = $quantity; } } } } } if (count($products)) { $cart = $this->emptyCart(); foreach ($products as $product_id => $data) { $product = Mage::getModel('catalog/product')->load($product_id); $cart->addProduct($product, $data); } $cart->save(); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); } } }