0

我对 Magento 自定义模块还很陌生,只想指出正确的方向来阅读内容。

我正在创建一些网站,我希望通过 API(我正在开发)动态更新它们的库存。

目前,我有一个每天运行的脚本,以使用当前库存数量更新每个产品,另一个脚本可以获取自上次更新以来的差异并执行一次(每 10 分钟一次)。

我不喜欢它,因为仍有出错的余地,而且它不适合我。我想要的是当您单击产品时,它会进行 API 调用、更新我的自定义字段并呈现页面。我还有一个自定义库存状态插件,所以我真的需要它在页面加载之前进行调用。. 如果 API 有问题,我可以在超时时编写一些逻辑来呈现页面。

任何指针都会非常有帮助。

4

2 回答 2

0

您可以使用事件/观察者功能来调用 API。尝试以下事件之一:-

catalog_controller_product_init_before
catalog_controller_product_init_after
catalog_controller_product_view
于 2019-03-11T06:50:05.110 回答
0

得到它的工作......感谢您的帮助,还有一些工作要做,但它在正确的时间调用脚本!谢谢

事件.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_controller_product_init_after">
        <observer name="Apicall" instance="Olisco\Tpcconnector\Observer\ApiCall" />
    </event>
</config>


<?php
namespace Olisco\Tpcconnector\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

class ApiCall implements ObserverInterface
{

    public function execute(EventObserver $observer)
    {
      #Code here to execute!
    }
}


于 2019-04-04T07:01:04.220 回答