如何在product_add_after事件中获取product_id?

时间:2019-06-04 22:24:40

标签: opencart opencart-3

我有一个在OpenCart 3.0.3.1中的after_product_add事件上触发的模块。在代码中,我想向产品添加信息,但是要做到这一点,我需要product_id,它不包含在从事件中获取的数据数组中。

除了更改OpenCart的源代码外,有人知道解决方案吗?

背景信息: 该模块将在创建后将产品与另一个系统同步,我想将GUID存储在数据库中。为此,我需要product_id。

我从事件触发器获得的数组是: 数组 (     [0] =>数组         (             [product_description] =>数组                 (                     [1] =>数组                         (                             [名称] => test25                             [说明] =>                             [meta_title] => test25                             [meta_description] =>                             [meta_keyword] =>                             [标签] =>                         )

(\{(.+?)\}(.+?){(.+?)\})

我搜索了论坛和开发人员文档。我发现的唯一参考资料告诉我,没有比我已经拥有的更多的信息了。我试图从请求中获取产品ID

            )

        [model] => test25
        [sku] => 
        [upc] => 
        [ean] => 
        [jan] => 
        [isbn] => 
        [mpn] => 
        [location] => 
        [price] => 
        [tax_class_id] => 0
        [quantity] => 1
        [minimum] => 1
        [subtract] => 1
        [stock_status_id] => 6
        [shipping] => 1
        [date_available] => 2019-06-04
        [length] => 
        [width] => 
        [height] => 
        [length_class_id] => 1
        [weight] => 
        [weight_class_id] => 1
        [status] => 1
        [sort_order] => 1
        [manufacturer] => 
        [manufacturer_id] => 0
        [category] => 
        [filter] => 
        [product_store] => Array
            (
                [0] => 0
            )

        [download] => 
        [related] => 
        [option] => 
        [image] => 
        [points] => 
        [product_reward] => Array
            (
                [1] => Array
                    (
                        [points] => 
                    )

            )

        [product_seo_url] => Array
            (
                [0] => Array
                    (
                        [1] => 
                    )

            )

        [product_layout] => Array
            (
                [0] => 
            )

    )

我想获取刚刚创建的产品的product_id,因此可以使用它向其中添加信息。

1 个答案:

答案 0 :(得分:0)

任何人都在寻找答案,这要归功于OpenCart论坛上的DigitCart,product_id作为事件操作的第三个变量发送。因此,您可以按以下方式获取产品ID:

public function createproduct($route, $args, $product_id) {
 // Do your thing
}