doupi3874 2014-02-17 23:13
浏览 40

为什么Magento会在简单地添加一个项目后自动考虑放弃购物车?

Bit of Background

A client is using Bronto to send emails to site visitors that have abandoned their shopping cart in Magento. Bronto grabs the Abandoned Carts from Magento's reports. The issue that the client ran into is that he noticed that shopping carts that have been placed as orders in Magento are not being removed from the abandoned shopping cart report causing him to accidentally send emails about an abandoned cart to customers that have already placed the order.

What I did

I took a look and tried to find one main reason why this occurred, but I couldn't find any. I tried doing a test order myself and noticed that as soon as I add an item to the shopping cart my cart is considered an abandoned cart. I think to myself "weird, this should consider it abandoned if my session expires and I haven't checked-out." I did a bit of research to see if anyone had this same exact issue, but no luck, close though. The next step that I took was turn on Persistent Shopping Cart. I turned on persistence, but that didn't help because my cart was still being sent to the Abandoned Carts report. Even after I checked-out the cart remained in the report. I then created a Module that observed the sales_order_place_after event. This module checks the order after being placed and inactivates the quote("the abandoned cart" when a user is logged-in) that the order was created from. Inactivating the quote removes the cart from the abandoned carts report. This works fine but some quotes seem to slip through the cracks and don't get set to inactive, not sure why.

My Questions

1. Why does Magento automatically consider a cart abandoned as soon as you add an item to it?

2. Where and how can I change this?

3. Why doesn't the persistent shopping cart do what it's said to do? (not send cart to abandoned cart unless the persistent session expires or am I just not understanding the persistent shopping cart functionality, please explain)

4. What causes some of the quotes not to be set to inactive by my module?(I've shown the code below. config.xml and Observer.php)

5. Am I using the correct event?

config.xml

<config> 
    <modules>
        <RIS_AbandonedCartCleanUp>
            <version>0.0.1</version>
        </RIS_AbandonedCartCleanUp>
    </modules>

    <global>

      <!-- Define the Model -->
      <models>
        <abandonedcartcleanup>
          <class>RIS_AbandonedCartCleanUp_Model</class>
        </abandonedcartcleanup>
      </models>

      <events>
        <sales_order_place_after>
          <observers>
            <abandonedcartcleanup>
              <type>singleton</type>
              <class>RIS_AbandonedCartCleanUp_Model_Observer</class>
              <method>remove_order_quote</method>
            </abandonedcartcleanup>
          </observers>
        </sales_order_place_after>
      </events>

    </global>

</config>

Observer.php

 <?php 

    class RIS_AbandonedCartCleanUp_Model_Observer{

    public function __construct(){
    }

    //Keep an eye out for when all the sales order saves have been committed
    public function remove_order_quote($observer){

        // Gets the order which is being saved.
        $order  = $observer->getOrder();
        $quoteId = $order->getQuoteId(); 

            //Get the quote for this specific order
        $quote = Mage::getModel('sales/quote')->load($quoteId);

            //Check if the quote is active
        if($quote->getIsActive() == 1){

              //set the quote to inactive and save
          $quote->setIsActive('0')
              ->save();
        }
    } 
    }

?>
  • 写回答

1条回答 默认 最新

  • doutui8842 2014-02-18 14:02
    关注

    I cannot fully answer this but I will give it my best shot. First off, you say:

    Even after I checked-out the cart remained in the report.

    If you are quite sure of this, there is something going on that I cannot explain and some of the following points may be moot.

    Question 1

    If you find Collection.php in app\code\core\Mage\Reports\Model\Resource\Quote and copy it to app\code\local\Mage\Reports\Model\Resource\Quote and add

    var_dump((string)$this->getSelect());
    

    in the prepareForAbandonedReport function (just before it returns), you will see the query that Magento uses to produce the Abandoned carts report. In my case, it's:

    SELECT `main_table`.*, (main_table.base_subtotal_with_discount*main_table.base_to_global_rate) AS `subtotal`, `cust_email`.`email`, `cust_fname`.`value` AS `firstname`, `cust_lname`.`value` AS `lastname`, CONCAT_WS(' ', cust_fname.value, cust_lname.value) AS `customer_name` 
        FROM `sales_flat_quote` AS `main_table` 
        INNER JOIN `customer_entity` AS `cust_email` ON cust_email.entity_id = main_table.customer_id 
        INNER JOIN `customer_entity_varchar` AS `cust_fname` ON cust_fname.entity_id = main_table.customer_id AND cust_fname.attribute_id = 5 
        INNER JOIN `customer_entity_varchar` AS `cust_lname` ON cust_lname.entity_id = main_table.customer_id AND cust_lname.attribute_id = 7 
        WHERE (items_count != '0') AND (main_table.is_active = '1')
    

    As you can see, it does not check any date or time values. It simply considers a cart abandoned if there is something in it and it's active, i.e. it has not been checked out yet. (Also, interestingly, it does not bother to look for abandoned carts from users that were not logged in.)

    In other words, a cart is considered to be abandoned until it's checked out. The customers who got an email even though they had completed their order, may have been "lined up" for an email by Bronto just before they checked out.

    Question 2

    You could modify the above mentioned query by adding some condition to the effect of "updated_at is before session expiration time" but that will probably just change the report and not what Bronto does, since Bronto may be using its own query. The fact that they claim they can spot carts abandoned by guest users seems to suggest this.

    Question 3

    At http://www.magentocommerce.com/knowledge-base/entry/setting-up-a-persistent-shopping-cart, it says:

    A persistent shopping cart keeps track of unpurchased items left in the cart, and saves the information for the customer’s next visit.

    I think that is pretty much all it does. Persistent shopping carts are merely saved for when the user returns. This in itself is not contradictory to them having an abandoned status.

    Questions 4 and 5

    As far as I can see, your code looks fine. But it really shouldn't be necessary to set the quote to inactive. Magento should take care of that by default and if it doesn't, like I said at the beginning, you have something going on that I cannot immediately explain

    +1 for the care you took in phrasing your question BTW.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了