2016-02-10 129 views
1

我正在使用hookActionProductUpdate。我正在获取所有数据更新但不包含属性。Prestashop产品更新挂钩未更新挂钩功能中的产品属性

这是钩子函数内部的代码:别的

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

一切都在更新,但前面的功能我得到的是一个较老。任何想法?


编辑:我想这太,这里是我的新功能:

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

回答

0

你并不需要实例化一个新的对象。产品对象应已包含在$params['product']中。

这里是产品类别的update()方法,其中这个钩子被称为:

public function update($null_values = false) 
{ 
    $return = parent::update($null_values); 
    $this->setGroupReduction(); 

    // Sync stock Reference, EAN13 and UPC 
    if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && StockAvailable::dependsOnStock($this->id, Context::getContext()->shop->id)) { 
     Db::getInstance()->update('stock', array(
      'reference' => pSQL($this->reference), 
      'ean13'  => pSQL($this->ean13), 
      'upc'  => pSQL($this->upc), 
     ), 'id_product = '.(int)$this->id.' AND id_product_attribute = 0'); 
    } 

    Hook::exec('actionProductSave', array('id_product' => (int)$this->id, 'product' => $this)); 
    Hook::exec('actionProductUpdate', array('id_product' => (int)$this->id, 'product' => $this)); 
    if ($this->getType() == Product::PTYPE_VIRTUAL && $this->active && !Configuration::get('PS_VIRTUAL_PROD_FEATURE_ACTIVE')) { 
     Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', '1'); 
    } 

    return $return; 
} 

然后,您应该使用此代码来代替:

public function hookActionProductUpdate($params) { 
    $product = $params['product']; 
    $arrrs = $product->getFrontFeatures(1); 
} 
+0

它不工作,@弗洛里安我已经更新了我的问题,看看。 –

+0

那么,你必须在类中调用'public static function getFrontFeaturesStatic()'方法'/ classes/Product.php'和'var_dump()'和'die()'来看看发生了什么。 –

+0

我刚发布了一个答案。你能不能告诉我该怎么做才能获得更新的功能。 –

0

是啊,我明白了,为什么,它在一个错误它叫挂钩AdminProductsController

从更新方法是ca先填充然后执行特征更新代码。

INSIDE processupdate功能

我发现这个代码

//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(); 
        }