If you have any idea then please share here.
On the Mage_Customer_Model_Session model's method setCustomerAsLoggedIn() an event customer_login is being dispatched. I guess you need to hook in on that event. You could do this as follows.
Add the event to your module's config.xml file (app/code/local/Lpf/ModuleCookie/etc/config.xml):
<?xml version="1.0"?>
<config>
<modules>
<Lpf_ModuleCookie>
<version>0.1</version>
</Lpf_ModuleCookie>
</modules>
<global>
<models>
<lpf_modulecookie>
<class>Lpf_ModuleCookie_Model</class>
</lpf_modulecookie>
</models>
</global>
<frontend>
<events>
<customer_login>
<observers>
<lpf_modulecookie_customer_login>
<type>model</type>
<class>lpf_modulecookie/observer</class>
<method>customerLogin</method>
</lpf_modulecookie_customer_login>
</observers>
</customer_login>
</events>
</frontend>
Now create a model Lpf_ModuleCookie_Model_Observer (app/code/local/Lpf/ModuleCookie/Model/Observer.php). Add a customerLogin() method to the class:
<?php
class Lpf_ModuleCookie_Model_Observer
{
/**
* Run couple of 'php' codes after customer logs in
*
* @param Varien_Event_Observer $observer
*/
public function customerLogin($observer)
{
$quote = Mage::getModel('checkout/session')->getQuote();
foreach ($quote->getAllItems() as $item)
{
$item->isDeleted(true);
if ($item->getHasChildren()) {
foreach ($item->getChildren() as $child) {
$child->isDeleted(true);
}
}
}
$quote->collectTotals()->save();
}
}
Reference : How to bind an action after customer login success using Magento?
-
-
-
-
-
if we print anything before Mage::getSingleton('checkout/cart')->truncate(); then displayed but not delete cart items. – Ashish Kacha Apr 16 '18 at 7:35
Use this event sales_quote_merge_before
Put this in config.xml
In below-mentioned code, we are using sales_quote_merge_before
observer to clear old items.
<events>
<sales_quote_merge_before><!--calling this event before merging the old cart with newly added cart items while login-->
<observers>
<ws_clearoldcartproducts_observer><!--unique identifier name for our observer-->
<type>singleton</type>
<class>Ws_Clearoldcartproducts_Model_Observer</class><!--Our observer class name-->
<method>loadCustomerQuote</method><!--Method to be called from our observer class-->
</ws_clearoldcartproducts_observer>
</observers>
</sales_quote_merge_before>
</events>
Put this in observer.php
public function loadCustomerQuote()
{
$customerQuote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId()
);
if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId())
{
// Removing old cart items of the customer.
foreach ($customerQuote->getAllItems() as $item)
{
$item->isDeleted(true);
if ($item->getHasChildren()) {
foreach ($item->getChildren() as $child) {
$child->isDeleted(true);
}
}
}
$customerQuote->collectTotals()->save();
}
else
{
$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();
$this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer()) ->setTotalsCollectedFlag(false) ->collectTotals() ->save();
}
return $this;
}
We have find this solution from this Link. Thanks to Surya for this solution.
Hope that'll help you.
-
@AshishKacha try this solution maybe that'll help you. – Emipro Technologies Pvt. Ltd. Apr 16 '18 at 7:04
-
@Ashish-Kacha Please let me know is that working for you or not.? – Emipro Technologies Pvt. Ltd. Apr 16 '18 at 7:09
-
1
-