/** * Change title of Inventoryplus * * @param type $observer */ public function inventoryplus_before_show_title($observer) { $title = $observer->getEvent()->getTitle(); $text = '<h3><a href="javascript:void(0);" onclick="showDashboardMenu();">' . '<span><i class="fa fa-th"></i> ERP Plus | Inventory Management </span></a></h3>'; $text .= '<div id="erp_menu_dashboard">' . Mage::app()->getLayout()->createBlock('erpplus/adminhtml_dashboard')->setTemplate('erp_plus/page/dashboard-menu.phtml')->toHtml() . '</div>'; $title->setText($text); }
/** * Add mass action in catalog > product view * @param type $observer */ public function addMassAction($observer) { $block = $observer->getEvent()->getBlock(); if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'catalog_product') { $block->addItem('BarcodeLabel', array('label' => Mage::helper('BarcodeLabel')->__('Print barcode labels'), 'url' => Mage::app()->getStore()->getUrl('BarcodeLabel/Admin/printSelectedProductLabel'))); } }
/** * Sets order STATE based on status. * * @param type $o */ public function orderState($o) { $order = $o->getEvent()->getOrder(); if (!is_object($order->getPayment())) { return $o; } $_c = $order->getPayment()->getMethod(); if (Mage::helper('sagepaysuite')->isSagePayMethod($_c) === false) { return $o; } $methodInstance = $order->getPayment()->getMethodInstance(); $methodInstance->setStore($order->getStoreId()); $action = $methodInstance->getConfigPaymentAction(); $state = Mage_Sales_Model_Order::STATE_NEW; if ($action == Ebizmarts_SagePaySuite_Model_Api_Payment::ACTION_AUTHORIZE_CAPTURE or $action == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) { $state = Mage_Sales_Model_Order::STATE_PROCESSING; } $order->setState($state); /* Set order status based on ReD response. * $sagedata = $this->_getTransactionsModel()->loadByParent($order->getId()); $ReD = $sagedata->getRedFraudResponse(); if(strtoupper($ReD) == 'DENY') { $order->setStatus('security_check'); }*/ }
/** * Checks * @param type $observer */ public function checkTax($observer) { $block = $observer->getEvent()->getBlock(); if ($block instanceof Mage_Checkout_Block_Total_Tax && $block->getTotal()) { $block->setTemplate('rewards/checkout/total/tax.phtml'); $total = $block->getTotal()->getValue(); // If tax is included in the produt price then we should subtract the change in tax price from the // tax total visually only. $store = $block->getTotal()->getAddress()->getQuote()->getStore(); if (Mage::helper('tax')->priceIncludesTax($store)) { $total -= $block->getTotal()->getAddress()->getQuote()->getRewardsDiscountTaxAmount(); } $block->setTotalInclCatalogDiscounts($total); } }
/** * * @param type $observer * @return void */ public function customerLogin($observer) { $customer = $observer->getEvent()->getCustomer(); $session = Mage::getSingleton('customer/session'); $latchId = $customer->getData('latch_id'); if ($latchId) { /* @var $latchHelper Joc_Latch_Helper_Data */ $latchHelper = Mage::helper('latch'); $latchEnabled = $latchHelper->getIfLatchEnabled($latchId, $customer->getId()); if ($latchEnabled['status'] == 1) { $session->setId(null)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->getCookie()->delete('customer'); Mage::getSingleton('core/session')->addError($latchEnabled['message']); } return; } }
/** * Approve an affiliate point transfer if the admin has the option enabled to * auto approve pending transfers * * @param type $observer * @return TBT_RewardsReferral_Model_Observer_Sales_Order_Invoice_Pay */ public function approvePoints($observer) { $order = $observer->getEvent()->getInvoice()->getOrder(); if (!$order) { return $this; } if (!Mage::helper('rewards/config')->shouldApprovePointsOnInvoice()) { return $this; } $collectionReference = Mage::getResourceModel('rewardsref/referral_order_transfer_reference_collection'); /* @var TBT_RewardsReferral_Model_Mysql4_Referral_Order_Transfer_Reference_Collection */ $collectionReference->addTransferInfo(); $collectionReference->filterAssociatedWithOrder($order->getId()); $collectionReference->addFieldToFilter('status', array('eq' => TBT_Rewards_Model_Transfer_Status::STATUS_PENDING_EVENT)); $this->_approvateTransferReferences($collectionReference); return $this; }
/** * When a pending customer registers we are assigning him the shared volume license. * @param type $observer */ public function assignVolumelicense($observer) { $event = $observer->getEvent(); $customer = $event->getCustomer(); $email = $customer->getEmail(); $shareaccess = Mage::getModel('volumelicense/registry')->getCollection()->getBySharedEmail($email); // Mage::log(''.$shareaccess->getSelect(),null,'access.log'); if (sizeof($shareaccess) != 0) { foreach ($shareaccess as $share) { // Mage::log($share->getData(),null,'access.log'); $sharemodel = Mage::getModel('volumelicense/registry')->load($share->getId()); $sharemodel->setAssignStatus(1); $sharemodel->setAssignCustomerId($customer->getEntityId()); $sharemodel->setUpdateTime(date('m/d/y h:i:s', time())); $sharemodel->save(); } } }
/** * Sets order STATE based on status. * * @param type $o */ public function orderState($o) { $order = $o->getEvent()->getOrder(); if (!is_object($order->getPayment())) { return $o; } $_c = $order->getPayment()->getMethod(); if (Mage::helper('sagepaysuite')->isSagePayMethod($_c) === false) { return $o; } $methodInstance = $order->getPayment()->getMethodInstance(); $methodInstance->setStore($order->getStoreId()); $action = $methodInstance->getConfigPaymentAction(); $state = Mage_Sales_Model_Order::STATE_NEW; if ($action == Ebizmarts_SagePaySuite_Model_Api_Payment::ACTION_AUTHORIZE_CAPTURE or $action == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) { $state = Mage_Sales_Model_Order::STATE_PROCESSING; } $order->setState($state); }
/** * Add mass-actions to the sales order grid, the non-intrusive way. * @param type $observer */ public function core_block_abstract_prepare_layout_after($observer) { $block = $observer->getEvent()->getBlock(); #Mage::log('XTENTO - Controller name is: '.$block->getRequest()->getControllerName(), null, '', true); if (in_array($block->getRequest()->getControllerName(), $this->getControllerNames())) { $isSecure = Mage::app()->getStore()->isCurrentlySecure() ? true : false; if ($block->getRequest()->getActionName() !== 'exportCsv' && $block->getRequest()->getActionName() !== 'exportExcel') { // Do not add columns if admin is exporting orders using the built-in Magento CSV/Excel XML export - you don't want the carrier dropdown/select there if (($block instanceof Mage_Adminhtml_Block_Widget_Grid || $block instanceof Enterprise_SalesArchive_Block_Adminhtml_Sales_Order_Grid) && $block->getId() == 'sales_order_grid') { if (Mage::getStoreConfigFlag('gridactions/general/add_trackingnumber_from_grid') && Mage::helper('gridactions')->getModuleEnabled()) { // Add tracking & carrier fields to grid if (Mage::getStoreConfigFlag('gridactions/general/add_trackingnumber_from_grid_combined')) { $block->addColumn('combined-input', array('header' => Mage::helper('gridactions')->__('Carrier / Tracking'), 'type' => 'text', 'sortable' => false, 'renderer' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Combined', 'filter' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Combined', 'width' => 190)); } else { $block->addColumn('carrier-selector', array('header' => Mage::helper('gridactions')->__('Shipping Carrier'), 'type' => 'text', 'sortable' => false, 'renderer' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Carrier', 'filter' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Carrier', 'width' => 190)); $block->addColumn('tracking-input', array('header' => Mage::helper('gridactions')->__('Tracking Number'), 'type' => 'text', 'sortable' => false, 'renderer' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Trackingnumber', 'filter' => 'Xtento_GridActions_Block_Adminhtml_Sales_Order_Grid_Widget_Renderer_Trackingnumber', 'width' => 170, 'after' => 'carrier-selector')); } } } } if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction || $block instanceof Enterprise_SalesArchive_Block_Adminhtml_Sales_Order_Grid_Massaction) { if (!$this->_initBlocks($block)) { return; } if (Mage::registry('moduleString') !== 'false') { return; } $enabledActions = explode(",", Mage::getStoreConfig('gridactions/general/actions')); // Add mass-actions to the sales order grid $actions = Mage::getModel('gridactions/system_config_source_actions')->toOptionArray(); foreach ($actions as $action) { $actionCode = $action['value']; $actionName = $action['label']; if (!in_array($actionCode, $enabledActions) && isset($enabledActions[0]) && $enabledActions[0] !== 'all') { continue; } if ($this->_isAllowed($actionCode)) { $block->addItem($actionCode, array('label' => Mage::helper('gridactions')->__($actionName), 'url' => Mage::app()->getStore()->getUrl('*/gridactions_grid/mass', array('actions' => $actionCode, '_secure' => $isSecure)), 'selected' => $actionCode == 'invoice' ? true : false)); } } } } }
/** * Update buttons in Sales Order * * @param type $observer */ public function changeButton($observer) { if (!Mage::helper('inventoryplus')->isInInventorySection()) { return; } $block = $observer->getEvent()->getBlock(); if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_Shipment_View') { $shipmentId = $block->getRequest()->getParam('shipment_id'); $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId); $orderId = $shipment->getOrderId(); $block->removeButton('save'); $block->removeButton('delete'); $block->updateButton('back', 'onclick', 'setLocation(\'' . $block->getUrl('adminhtml/sales_order/view', array('order_id' => $orderId, 'active_tab' => 'order_shipments', 'inventoryplus' => '1')) . '\')'); } if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_Shipment_Create' && $block->getRequest()->getParam('inventoryplus') == '1') { $orderId = $block->getRequest()->getParam('order_id'); $block->updateButton('back', 'onclick', 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('adminhtml/ins_inventoryshipment/index') . '\')'); } if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_View') { $orderId = $block->getRequest()->getParam('order_id'); $block->removeButton('print'); $block->removeButton('save'); $block->removeButton('delete'); $block->removeButton('order_hold'); $block->removeButton('order_unhold'); $block->removeButton('void_payment'); $block->removeButton('accept_payment'); $block->removeButton('deny_payment'); $block->removeButton('get_review_payment_update'); $block->removeButton('send_notification'); $block->removeButton('void_payment'); $block->removeButton('order_reorder'); $block->removeButton('order_edit'); $block->removeButton('order_cancel'); $block->removeButton('order_creditmemo'); $block->removeButton('order_invoice'); $block->updateButton('order_ship', 'onclick', 'setLocation(\'' . $block->getUrl('adminhtml/sales_order_shipment/new', array('order_id' => $orderId, 'inventoryplus' => '1')) . '\')'); $block->updateButton('back', 'onclick', 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('adminhtml/ins_inventoryshipment/index') . '\')'); } }
/** * When a pending customer registers we are assigning him the shared volume license. * @param type $observer */ public function assignVolumelicense($observer) { $event = $observer->getEvent(); $customer = $event->getCustomer(); if ($customer) { $email = $customer->getEmail(); $order = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('future_email', $email); if (sizeof($order) != 0) { foreach ($order as $od) { $od->setCustomerFirstname($customer->getFirstname()); $od->setCustomerLastname($customer->getLastname()); $newCustomerEmail = $customer->getEmail(); $od->setCustomerId($customer->getId()); $od->setCustomerEmail($customer->getEmail()); $od->setFutureEmail(NULL); // $od->addStatusHistoryComment('The owner has been changed from customer: ' . $oldCustomerEmail . ' to customer: ' . $customer->getEmail() . ' by user ' . Mage::getSingleton('admin/session')->getUser()->getUsername()); $items = $od->getAllItems(); try { $od->save(); foreach ($items as $item) { if ($item->getProductType() == 'downloadable') { $downloadableLinks = Mage::getModel('downloadable/link_purchased')->getCollection()->addFieldToFilter('order_item_id', $item->getItemId()); foreach ($downloadableLinks->getItems() as $link) { $link->setCustomerId($customer->getId()); $link->save(); } } } /* $parent_order_id = $od->getParentOrderId(); $parentOrderData = Mage::getModel('sales/order')->load($parent_order_id); $parentEmail = $parentOrderData->getCustomerEmail(); */ // $helper->volumeLicenseShareEmail($toEmail,$purchasingAgentMailData,$parentEmail); } catch (Exception $e) { Mage::log($e->getMessage()); } } } } }
/** * Attach to sales_order_save_after event * * @see sales_order_save_after * @param type $observer */ public function prepareOrderForDataSync($observer) { if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log')) { Mage::log("TRIGGERED prepareOrderForDataSync"); } $order = $observer->getEvent()->getOrder(); /* @var $order Mage_Sales_Model_Order */ $customerId = $order->getCustomerId(); //$customer = Mage::getmodel('customer/customer')->load($customerId); /* @var $customer Mage_Customer_Model_Customer */ if ($this->_hasCustomerDataSynced) { return; // Don't bother if nothing has updated. } //$storeId = $customer->getStoreId(); // Is this always correct?? $storeId = $order->getStoreId(); if ($customerId) { self::setCustomerForDataSync($customerId, $storeId); $this->_hasCustomerDataSynced = TRUE; } }
/** * Event: customer_load_after * * Attach the customer's CIM id to the customer profile when loaded * * @param type $observer * @return Gorilla_AuthorizenetCim_Model_Observer */ public function loadPaymentechInfo($observer) { $customer = $observer->getEvent()->getCustomer(); Mage::getModel('chasepaymentech/profile')->loadInfoByCustomer($customer); return $this; }
/** * Catch event inp_get_current_username to switch to webpos user * * @param type $observer */ public function inp_get_current_username($observer) { $user = $observer->getEvent()->getUser(); if ($user->getUsername()) { return; } if (!Mage::helper('inventoryplus')->isWebPOS20Active()) { return; } if ($curUser = Mage::getSingleton('webpos/session')->getUser()) { $user->setUsername($curUser->getUsername()); } }
/** * Track add to cart * @param type $observer */ public function productAddCart($observer) { try { $product = $observer->getEvent()->getProduct(); $table = Intelivemetrics_Unityreports_Model_Utils::getTableName('unityreports/product_counters'); $query = "INSERT INTO {$table} (product_id,addtocarts,last_updated_at) VALUES ({$product->getEntityId()},1,NOW())\n ON DUPLICATE KEY UPDATE addtocarts = addtocarts+1,last_updated_at=NOW();"; Mage::getSingleton('unityreports/utils')->getDb()->query($query); //track customer action $customer = Mage::getModel('unityreports/customer'); if ($customer->isKnown()) { $customer->trackAdd2cart($product->getSku()); } Mage::getSingleton('unityreports/utils')->getDb()->closeConnection(); } catch (Exception $ex) { Mage::helper('unityreports')->debug($ex->getMessage(), Zend_Log::ERR); Mage::helper('unityreports')->debug('FILE: ' . __FILE__ . 'LINE: ' . __LINE__); } }
/** * EVENT LISTENER * Catalog product save check on document id * @param type $observer */ public function prepareProductSave($observer) { $product = $observer->getEvent()->getProduct(); if ($product->getWeb2printDocumentId()) { if (count($product->getWebsiteIds()) > 1) { Mage::throwException('A web2print product can only contain to 1 website. Product not saved'); } } }
/** * * @param type $observer * @return type */ public function addTierFieldToProgram($observer) { /* hainh edit 25-04-2014 */ if (!Mage::helper('affiliatepluslevel')->isPluginEnabled()) { return; } $form = $observer->getEvent()->getForm(); $data = $observer->getEvent()->getFormData(); $fieldset = $observer->getEvent()->getFieldset(); // $fieldset = $form->addFieldset('tiers_fieldset',array( // 'legend' => Mage::helper('affiliatepluslevel')->__('Tier Commission') // )); $inStore = Mage::app()->getRequest()->getParam('store'); $defaultLabel = Mage::helper('affiliateplusprogram')->__('Use Default'); $defaultTitle = Mage::helper('affiliateplusprogram')->__('-- Please Select --'); $scopeLabel = Mage::helper('affiliateplusprogram')->__('STORE VIEW'); $fieldset->addField('multilevel_separator', 'text', array('label' => Mage::helper('affiliatepluslevel')->__('Tier Commission'), 'comment' => '10px'))->setRenderer(Mage::app()->getLayout()->createBlock('affiliateplus/adminhtml_field_separator')); $inStoreData = isset($data['use_tier_config_in_store']) ? $data['use_tier_config_in_store'] : false; $fieldset->addField('use_tier_config', 'select', array('name' => 'use_tier_config', 'label' => Mage::helper('affiliatepluslevel')->__('Use General Configuration'), 'title' => Mage::helper('affiliatepluslevel')->__('Use General Configuration'), 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(), 'disabled' => $inStore && !$inStoreData, 'after_element_html' => ($inStore ? '</td><td class="use-default"> <input id="use_tier_config_default" name="use_tier_config_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($inStoreData ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="use_tier_config_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td>' : '') . '</td><td class="scope-label"> [' . $scopeLabel . ']<script type="text/javascript"> function changeTierConfig(){ var config = $(\'affiliateplusprogram_use_tier_config\').value; if (config == 1){ $(\'affiliateplusprogram_max_level\').parentNode.parentNode.hide(); $(\'grid_tier_commission\').parentNode.parentNode.hide(); $(\'grid_sec_tier_commission\').parentNode.parentNode.hide(); $(\'affiliateplusprogram_use_sec_tier\').parentNode.parentNode.hide(); }else{ $(\'affiliateplusprogram_max_level\').parentNode.parentNode.show(); $(\'grid_tier_commission\').parentNode.parentNode.show(); $(\'affiliateplusprogram_use_sec_tier\').parentNode.parentNode.show(); changeSecTierConfig(); } } function changeSecTierConfig() { if ($(\'affiliateplusprogram_use_sec_tier\').value == 1) { $(\'grid_sec_tier_commission\').parentNode.parentNode.show(); } else { $(\'grid_sec_tier_commission\').parentNode.parentNode.hide(); } } Event.observe(window,\'load\',changeTierConfig); </script>', 'onchange' => 'changeTierConfig()')); $inStoreData = isset($data['max_level_in_store']) ? $data['max_level_in_store'] : false; $fieldset->addField('max_level', 'text', array('name' => 'max_level', 'label' => Mage::helper('affiliatepluslevel')->__('Number of Tiers to Enable'), 'title' => Mage::helper('affiliatepluslevel')->__('Number of Tiers to Enable'), 'disabled' => $inStore && !$inStoreData, 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="max_level_default" name="max_level_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($inStoreData ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="max_level_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']')); $inStoreData = isset($data['tier_commission_in_store']) ? $data['tier_commission_in_store'] : false; $fieldset->addField('tier_commission', 'text', array('name' => 'tier_commission', 'label' => Mage::helper('affiliatepluslevel')->__('Tier Commission Value & Type'), 'title' => Mage::helper('affiliatepluslevel')->__('Tier Commission Value & Type'), 'disabled' => $inStore && !$inStoreData, 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="tier_commission_default" name="tier_commission_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($inStoreData ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="tier_commission_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']'))->setRenderer(Mage::app()->getLayout()->createBlock('affiliatepluslevel/adminhtml_program_tier')->setProgramData($data)); $inStoreData = isset($data['use_sec_tier_in_store']) ? $data['use_sec_tier_in_store'] : false; $fieldset->addField('use_sec_tier', 'select', array('name' => 'use_sec_tier', 'label' => Mage::helper('affiliatepluslevel')->__('Use different commission from 2nd order of a Customer'), 'title' => Mage::helper('affiliatepluslevel')->__('Use different commission from 2nd order of a Customer'), 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(), 'disabled' => $inStore && !$inStoreData, 'after_element_html' => '<p class="note">' . Mage::helper('affiliatepluslevel')->__('Select "No" to apply above commission for all orders') . '</p>' . ($inStore ? '</td><td class="use-default"> <input id="use_sec_tier_default" name="use_sec_tier_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($inStoreData ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="use_sec_tier_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td>' : '') . '</td><td class="scope-label"> [' . $scopeLabel . ']', 'onchange' => 'changeSecTierConfig()')); $inStoreData = isset($data['sec_tier_commission_in_store']) ? $data['sec_tier_commission_in_store'] : false; $fieldset->addField('sec_tier_commission', 'text', array('name' => 'sec_tier_commission', 'label' => Mage::helper('affiliatepluslevel')->__('Tier Commission Value & Type (from 2nd order)'), 'title' => Mage::helper('affiliatepluslevel')->__('Tier Commission Value & Type (from 2nd order)'), 'disabled' => $inStore && !$inStoreData, 'after_element_html' => $inStore ? '</td><td class="use-default"> <input id="sec_tier_commission_default" name="sec_tier_commission_default" type="checkbox" value="1" class="checkbox config-inherit" ' . ($inStoreData ? '' : 'checked="checked"') . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> <label for="sec_tier_commission_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label> </td><td class="scope-label"> [' . $scopeLabel . '] ' : '</td><td class="scope-label"> [' . $scopeLabel . ']'))->setRenderer(Mage::app()->getLayout()->createBlock('affiliatepluslevel/adminhtml_program_sectier')->setProgramData($data)); }
/** * process coupon post apply * @param type $observer * @return Magestore_RewardPointsReferFriends_Model_Observer */ public function couponPost($observer) { if (Mage::helper('rewardpointsreferfriends')->getReferConfig('refer_method') == 'link') { return $this; } $action = $observer->getEvent()->getControllerAction(); $code = trim($action->getRequest()->getParam('coupon_code')); if (!$code) { return $this; } $refer_cus = Mage::getModel('rewardpointsreferfriends/rewardpointsrefercustomer')->loadByCoupon($code); $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId(); if (!$refer_cus->getId() || $refer_cus->getCustomerId() == $customerId) { return $this->useDefaultCoupon(); } $allowUseCoupon = Mage::helper('rewardpointsreferfriends/calculation_earning')->checkUsesPerCustomer(Mage::getSingleton('checkout/session')->getQuote()); if (!$allowUseCoupon) { Mage::getSingleton('checkout/session')->getMessages(true); Mage::getSingleton('checkout/session')->addError(Mage::helper('rewardpointsreferfriends')->__('You cannot use this coupon anymore.')); $this->useDefaultCoupon(); } else { if (!Mage::getSingleton('checkout/session')->getData('coupon_code')) { Mage::getSingleton('checkout/session')->setData('coupon_code', $code); } if ($action->getRequest()->getParam('remove') == 1) { if (Mage::getSingleton('checkout/session')->getData('coupon_code')) { Mage::getSingleton('checkout/session')->setData('coupon_code', ''); } if ($refer_cus->getKey() == Mage::getSingleton('core/cookie')->get('rewardpoints_offer_key')) { Mage::getSingleton('core/cookie')->delete('rewardpoints_offer_key'); Mage::getSingleton('checkout/session')->getMessages(true); Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('rewardpointsreferfriends')->__('Coupon code was canceled.')); } } else { Mage::getSingleton('core/cookie')->set('rewardpoints_offer_key', $refer_cus->getKey()); Mage::getSingleton('checkout/session')->getMessages(true); Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('rewardpointsreferfriends')->__('Coupon code "%s" was applied.', $code)); } } $action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $action->getResponse()->setRedirect(Mage::getUrl('checkout/cart')); }
/** * Add discount amount in the quote when partial payment * * @param type $observer */ public function addDiscountWhenPartial($observer) { $session = Mage::getSingleton('checkout/session'); if (!$session->getApprovalRequestSuccess() == 'partial') { $request = Mage::app()->getRequest(); if (Mage::app()->getRequest()->getActionName() != 'partialPost' && $request->getModuleName() != 'mundipagg' && $request->getControllerName() != 'standard') { return $this; } } $quote = $observer->getEvent()->getQuote(); $quoteid = $quote->getId(); $reservedOrderId = $quote->getReservedOrderId(); if (!$reservedOrderId) { return $this; } $order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId); if (!$order->getId()) { return $this; } $payment = $order->getPayment(); $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information'); $discountAmount = 0; if (isset($interestInformation)) { foreach ($interestInformation as $ii) { $discountAmount += (double) $ii->getValue(); } } if ($quoteid) { $total = $quote->getBaseSubtotal(); $quote->setSubtotal(0); $quote->setBaseSubtotal(0); $quote->setSubtotalWithDiscount(0); $quote->setBaseSubtotalWithDiscount(0); $quote->setGrandTotal(0); $quote->setBaseGrandTotal(0); $canAddItems = $quote->isVirtual() ? 'billing' : 'shipping'; foreach ($quote->getAllAddresses() as $address) { $discountAmount -= $address->getShippingAmount(); $address->setSubtotal(0); $address->setBaseSubtotal(0); $address->setGrandTotal(0); $address->setBaseGrandTotal(0); $address->collectTotals(); $quote->setSubtotal((double) $quote->getSubtotal() + $address->getSubtotal()); $quote->setBaseSubtotal((double) $quote->getBaseSubtotal() + $address->getBaseSubtotal()); $quote->setSubtotalWithDiscount((double) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()); $quote->setBaseSubtotalWithDiscount((double) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()); $quote->setGrandTotal((double) $quote->getGrandTotal() + $address->getGrandTotal()); $quote->setBaseGrandTotal((double) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal()); $quote->save(); $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)->save(); if ($address->getAddressType() == $canAddItems) { //echo $address->setDiscountAmount; exit; $address->setSubtotalWithDiscount((double) $address->getSubtotalWithDiscount() - $discountAmount); $address->setGrandTotal((double) $address->getGrandTotal() - $discountAmount); $address->setBaseSubtotalWithDiscount((double) $address->getBaseSubtotalWithDiscount() - $discountAmount); $address->setBaseGrandTotal((double) $address->getBaseGrandTotal() - $discountAmount); if ($address->getDiscountDescription()) { $address->setDiscountAmount(-($address->getDiscountAmount() - $discountAmount)); $address->setDiscountDescription($address->getDiscountDescription() . ', Discount to Partial Payment'); $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount() - $discountAmount)); } else { $address->setDiscountAmount(-$discountAmount); $address->setDiscountDescription('Discount to Partial Payment'); $address->setBaseDiscountAmount(-$discountAmount); } $address->save(); } } //echo $quote->getGrandTotal(); foreach ($quote->getAllItems() as $item) { //We apply discount amount based on the ratio between the GrandTotal and the RowTotal $rat = $item->getPriceInclTax() / $total; $ratdisc = $discountAmount * $rat; $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty()); $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save(); } } }