Prestashop 产品更新挂钩未在挂钩功能中更新产品属性 [英] Prestashop product update hook is not updating product attributes in the hook function

查看:52
本文介绍了Prestashop 产品更新挂钩未在挂钩功能中更新产品属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 hookActionProductUpdate.我正在更新所有数据,但没有更新属性.

I am using hookActionProductUpdate. I am getting all data updated but not attributes.

这是钩子函数里面的代码:

This is the code inside hook function:

public function hookActionProductUpdate($params) {
     $prestaObject = new ProductCore($params['id_product'], false, Context::getContext()->language->id);
     $arrrs = $prestaObject->getFrontFeatures(1); 
}

其他一切都已更新,但我获得的前端功能是较旧的.有什么想法吗?

Everything else is updated but the front features I am getting are the older one. Any IDEA?

编辑:我也试过了,这是我的新功能:

EDIT: I tried this too, here is my new function:

public function hookActionProductUpdate($params) {
    $product = $params['product'];
    $arrrs = $product->getFrontFeatures(1);
    pr($arrrs);die("No updating :(");
}

推荐答案

是的,我明白为什么,这是 prestashop 中的一个错误,它调用了钩子 AdminProductsController

Yeah I got it why, Its a bug in prestashop, It calls the hook AdminProductsController

Hook::exec('actionProductSave', array('id_product' => (int)$this->id, 'product' => $this));
Hook::exec('actionProductUpdate', array('id_product' => (int)$this->id, 'product' => $this));

从首先调用的更新方法开始,然后执行功能更新代码.

from an update method which is called first then it executes the feature update code.

INSIDE 进程更新函数

INSIDE processupdate function

我找到了这个代码

//this update method calls the HOOK and when this hook get executed it updates features in the database.
if ($object->update()) {
              // If the product doesn't exist in the current shop but exists in another shop
                if (Shop::getContext() == Shop::CONTEXT_SHOP && !$existing_product->isAssociatedToShop($this->context->shop->id)) {
                    $out_of_stock = StockAvailable::outOfStock($existing_product->id, $existing_product->id_shop_default);
                    $depends_on_stock = StockAvailable::dependsOnStock($existing_product->id, $existing_product->id_shop_default);
                    StockAvailable::setProductOutOfStock((int)$this->object->id, $out_of_stock, $this->context->shop->id);
                    StockAvailable::setProductDependsOnStock((int)$this->object->id, $depends_on_stock, $this->context->shop->id);
                }


                PrestaShopLogger::addLog(sprintf($this->l('%s modification', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
                if (in_array($this->context->shop->getContext(), array(Shop::CONTEXT_SHOP, Shop::CONTEXT_ALL))) {
                    if ($this->isTabSubmitted('Shipping')) {
                        $this->addCarriers();
                    }
                    if ($this->isTabSubmitted('Associations')) {
                        $this->updateAccessories($object);
                    }
                    if ($this->isTabSubmitted('Suppliers')) {
                        $this->processSuppliers();
                    }
                    if ($this->isTabSubmitted('Features')) {
                        $this->processFeatures();
                    }

这篇关于Prestashop 产品更新挂钩未在挂钩功能中更新产品属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆