Magento 购物车放弃从哪里开始?

发布于 2025-01-04 01:43:11 字数 981 浏览 0 评论 0原文

我正在尝试使用 Magento 的内置 cron 模块创建某种类型的购物车放弃系统。我基本上需要的是一个系统,该系统每 15 分钟检查一次废弃的购物车,如果每个购物车都满足特定条件,则将选择的购物车数据发送到另一个 Web 服务。

基本上这是我的过程(但请随意提出更好的方法):

过程

  1. 获取废弃购物车列表
  2. 对于每个废弃的购物车...
    • 向数据库中该购物车的 Deserted_duration 字段添加 15(分钟)
    • 检查abandoned_duration是否为45或1440(1天)或4320(3天)
      • 如果是的话,
        • 将购物车信息发送到另一个网络服务
        • 如果放弃的持续时间为 4320(3 天),
          • 删除废弃的购物车
      • 否则,
        • 继续
  3. 使用 Magento cron 每 15 分钟重复一次

问题

  1. 这在 Magento 中可行吗?
  2. 是否有更好的流程使用 Magento 来执行此操作?
  3. 实施此计划需要采取哪些步骤?例如...
    • 哪些核心模块是必需的?
    • 哪些控制器需要扩展?
    • 我应该为此创建自己的模块吗?
    • 以数组形式获取废弃购物车的最佳方法是什么?

我接触社区的原因是 Magento 文档和教程非常模糊。我是 Magento MVC 的新手,但我对 PHP、OOP 和 MVC 并不陌生。

这里的任何指导都是一流的。干杯。

I am attempting some type of shopping cart abandonment system with Magento using it's built-in cron module. What I basically need is a system that checks for abandoned shopping carts every 15 mins and sends select cart data to another web service if certain criteria is met with each cart.

Basically here is my process (but feel free to suggest a better way):

the process

  1. Get list of abandoned carts
  2. For each abandoned cart...
    • Add 15 (mins) to that cart's abandoned_duration field in database
    • Check if the abandoned_duration is at 45 or 1440 (1 day) or 4320 (3 days)
      • If yes,
        • send cart information to another web service
        • If abandoned_duration is at 4320 (3 days),
          • Delete abandoned cart
      • Else,
        • continue
  3. Repeat every 15 mins using Magento cron

the questions

  1. Is this possible in Magento?
  2. Is there a better process to do this using Magento?
  3. What are the steps needed to go about implementing this? For example...
    • Which core modules are necessary?
    • Which controllers need to be extended?
    • Should I create my own module for this?
    • What is the best way to get abandoned shopping carts as an array?

The reason I am reaching out to the community is because the Magento documentation and tutorials are very vague. I am new to the Magento MVC however I am not new to PHP, OOP, and MVCs.

Any guidance here would be stellar. Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸短情长 2025-01-11 01:43:11

所有这些都可以使用 Magento 来完成,但正如您所说,这是一个非常广泛的问题。我将给出特定主题的答案,但我建议您花时间研究 Magento 模块开发的基础知识。这是 Alan Storm 的优秀教程 (阅读整个系列)。

获取废弃购物车列表

在 Magento 中,购物车只是 sales/quote 对象的包装器,因此这就是您将使用的实体。
我建议您简单地检查 updated_at 字段,而不是将增量添加到废弃的_duration 属性中。

$adapter = Mage::getSingleton('core/resource')->getConnection('sales_read');
$minutes = 15;
$from = $adapter->getDateSubSql(
    $adapter->quote(now()), 
    $minutes, 
    Varien_Db_Adapter_Interface::INTERVAL_MINUTE
);
$quotes = Mage::getResourceModel('sales/quote_collection')
    ->addFieldToFilter('converted_at', $adapter->getSuggestedZeroDate())
    ->addFieldToFilter('updated_at', array('to' => $from));

这将为您提供 15 分钟内未更新的所有报价的集合(将其视为带有方法的数组)。您可以像数组一样迭代它们

foreach ($quotes as $quote) {
    /* @var $quote Mage_Sales_Model_Quote */
}

Magento Cronjobs

在 Magento 中,所有 cron 作业都列在配置结构中。因此,首先您需要将其添加到模块的 config.xml 中(有关 Magento 配置的更多信息,请参阅链接教程)。
此 XML 向 Magento 注册一个 cronjob。

<crontab>
    <jobs>
        <process_abandoned_carts>
            <schedule>
                <cron_expr>*/15 * * * *</cron_expr>
            </schedule>
            <run>
                <model>your_module/observer::processAbandonedCarts</model>
            </run>
        </process_abandoned_carts>
    </jobs>
</crontab>

现在,每当 Magento 运行 cronjob 时,它都会实例化 your_module/observer 类并调用 processAbandonedCarts() 方法。
为了让 Magento 处理配置的 cronjobs,您需要设置系统来执行此操作。这由两部分组成:系统配置和 cron 作业的触发。

系统配置在管理界面的系统> 下完成。配置>系统> Cron(计划任务)

触发包括设置一种定期执行 Magento 根目录中的 cron.php(或 cron.sh)脚本的方法。这可以使用常规的 crontab 条目来完成(在任何合适的 UNIX 系统上使用 man 5 crontab 了解更多信息)。许多人首选的另一个选项是通过 curlwget 调用执行 cron.php 脚本,以便处理用户 ID 与常规 Magento 用户 ID(即 Apache 用户)相匹配。如果配置了 APC 缓存,这可能很重要,但这已经偏离主题了。
然而,主题是您需要足够频繁地调用它,以便它与您在管理界面中指定的设置相匹配
我通常建议每 5 分钟执行一次 cron.php 脚本。如果没有安排任何内容,它将直接退出。

在使用 cronjobs 时,Magento 的一个非常有用的扩展是 Aoe_Scheduler。它添加了许多用于 cronjobs 的用户界面和交互功能,这些应该是核心系统的一部分。

其他

将数据发送到 Web 服务不是 Magento 特定的,而是常规 PHP,所以我不会详细介绍。

要删除购物车,只需在加载的 sales/quote 实例上调用 $quote->delete() 即可。

请询问更具体的问题以获取更多信息。

All this can be done using Magento, but as you said, this is a very broad question. I'll give answers to the specific topics, but I suggest you take time to study the fundamentals of Magento module development. Here is an excellent tutorial by Alan Storm (read the whole series).

Get list of abandoned carts

In Magento, the cart is simply a wrapper for the sales/quote object, so that is the entity you will be working with.
Instead of adding increments to a abandoned_duration attribute, I suggest simply checking against the updated_at field.

$adapter = Mage::getSingleton('core/resource')->getConnection('sales_read');
$minutes = 15;
$from = $adapter->getDateSubSql(
    $adapter->quote(now()), 
    $minutes, 
    Varien_Db_Adapter_Interface::INTERVAL_MINUTE
);
$quotes = Mage::getResourceModel('sales/quote_collection')
    ->addFieldToFilter('converted_at', $adapter->getSuggestedZeroDate())
    ->addFieldToFilter('updated_at', array('to' => $from));

This will give you a collection (think of it as an array with methods) of all quotes that haven't been updated for 15 minutes. You can iterate over them like an array

foreach ($quotes as $quote) {
    /* @var $quote Mage_Sales_Model_Quote */
}

Magento Cronjobs

In Magento, all cron jobs are listed in the configuration structure. So first you need to add it to the config.xml of your module (refer to the linked tutorial for more information on Magento configuration).
This XML registers a cronjob with Magento.

<crontab>
    <jobs>
        <process_abandoned_carts>
            <schedule>
                <cron_expr>*/15 * * * *</cron_expr>
            </schedule>
            <run>
                <model>your_module/observer::processAbandonedCarts</model>
            </run>
        </process_abandoned_carts>
    </jobs>
</crontab>

Now, whenever Magento runs the cronjob, it will instantiate the class your_module/observer and call the processAbandonedCarts() method.
In order for Magento to process configured cronjobs, you need to set the system up to do so. This consists of two parts: the system configuration and the triggering of the cron jobs.

The system configuration is done in the administrative interface under System > Configuration > System > Cron (Scheduled Tasks)

The triggering consists of setting up a way to periodically execute the cron.php (or cron.sh) script in the Magento root directory. This can be done using a regular crontab entry (man 5 crontab on any decent unix system for more information). Another option preferred by many is to execute the cron.php script through a curl or wget call so the processing user ID matches the regular Magento user ID (i.e. the Apache user). This might be important if APC caching is configured, but this is getting off topic.
However, on topic is that you need to call it often enough so it matches the settings you specify in the administrative interface!
I generally recommend executing the cron.php script every 5 minutes. If there is nothing scheduled it will simply exit.

One really useful extension for Magento when working with cronjobs is Aoe_Scheduler. It adds much of the user interfaces for cronjobs and interactive functionality that should be part of the core system.

Other

Sending the data to a web service is not Magento specific, but rather regular PHP, so I'll wont go into more detail.

To delete a cart, simple call $quote->delete() on the loaded sales/quote instance.

Please ask mor specific questions for further information.

鹿港小镇 2025-01-11 01:43:11

这是我的,可以获取所有活跃的废弃购物车报价

$quotes = Mage::getResourceModel('sales/quote_collection')
        ->addFieldToFilter('converted_at', array('null' => true))
        ->addFieldToFilter('customer_email', array('notnull' => true))
        ->addFieldToFilter('items_count', array('gteq' => 1))
        ->addFieldToFilter('customer_is_guest', array('eq' => 0))
        ->addFieldToFilter('customer_id', array('in' => $this->getCustomerIds()))

        ->addFieldToFilter('is_active', 1)

        //->addFieldToFilter('updated_at', array('to' => $from));
        ;

here is mine to get all active abandoned cart quotes

$quotes = Mage::getResourceModel('sales/quote_collection')
        ->addFieldToFilter('converted_at', array('null' => true))
        ->addFieldToFilter('customer_email', array('notnull' => true))
        ->addFieldToFilter('items_count', array('gteq' => 1))
        ->addFieldToFilter('customer_is_guest', array('eq' => 0))
        ->addFieldToFilter('customer_id', array('in' => $this->getCustomerIds()))

        ->addFieldToFilter('is_active', 1)

        //->addFieldToFilter('updated_at', array('to' => $from));
        ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文