Retrieve info from additional field to product list

DeividasJJ

I'm using this free module sample to add new video url field to the product. Everything works fine, I can see new data in product.tpl, but I cant get data to product-list.tpl what is very important to me, I want to add play button to each product. I found that for this purpose I have to use hookActionProductListOverride function but no luck with that. Anyone can help me?

public function hookDisplayAdminProductsExtra($params) {
    $id_product = Tools::getValue('id_product');
    $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
    if(!empty($sampleObj) && isset($sampleObj->id)){
        $this->context->smarty->assign(array(
            'belvg_textarea' => $sampleObj->textarea,
        ));
    }

    return $this->display(__FILE__, 'views/admin/sample.tpl');
}

public function hookActionProductUpdate($params) {
    $id_product = Tools::getValue('id_product');
    $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
    $sampleObj->textarea = Tools::getValue('belvg_sample');
    $sampleObj->id_product = $id_product;

    if(!empty($sampleObj) && isset($sampleObj->id)){
        $sampleObj->update();
    } else {
        $sampleObj->add();
    }
}

public function hookDisplayFooterProduct($params) {
    $id_product = Tools::getValue('id_product');
    $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
    if(!empty($sampleObj) && isset($sampleObj->id)){
        $this->context->smarty->assign(array(
            'belvg_textarea' => $sampleObj->textarea,
        ));
    }

    echo $sampleObj->textarea;
}
eapo

Wasn't easy to solve this and can be less ugly, but in my case working like a charm.

After lot of hours spent with the Belvg's module I've used this module, almost the same with same problem, but with language support and more flexibility: http://nemops.com/prestashop-products-new-tabs-fields

Needed to add multiple custom fields, so it's more detailed as the original questions requires:

    // adding more fields
    $sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang ADD `custom_field1`, `custom_field2` TEXT NOT NULL';
    ...

    // adding argument for the getCustomField() and multiply lines
    $this->context->smarty->assign(array(
        'custom_field1' => $this->getCustomField('custom_field1',(int)Tools::getValue('id_product')),
        'custom_field2' => $this->getCustomField('custom_field2',(int)Tools::getValue('id_product')),
    ...

    // expanding the actionProductUpdatea hook
        if(!Db::getInstance()->update('product_lang', array('custom_field1'=> pSQL(Tools::getValue('custom_field1_'.$lang['id_lang'])),'custom_field2'=> pSQL(Tools::getValue('custom_field2_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_product = ' .$id_product ))
    ...

    // this is the missing part!
    // upgrading the getCustomField() function to accept multiple custom fields and registering global vars
public function getCustomField($getKey,$id_product)
{
    $result = Db::getInstance()->ExecuteS('SELECT '.$getKey.', id_lang FROM '._DB_PREFIX_.'product_lang WHERE id_product = ' . (int)$id_product);

    if(!$result)
        return array();

    foreach ($result as $field) {
        $val=$field[$getKey];
        $fields[$field['id_lang']] = $val;
        if(!empty($val)){
            !Configuration::updateValue($getKey, $val);
        }
    }
    return $fields;
}

Calling the $custom_field1 and $custom_field2 in every .tpl working fine like this:

    {if $custom_field1}
        {if isset($custom_field1) && $custom_field1}
            <div>{$custom_field1}</div>
    {/if}
    {if $custom_field2}
        {if isset($custom_field2) && $custom_field2}
            <div>{$custom_field2}</div>
    {/if}

Hope someone also need this. Thank You!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Retrieve info from additional field to product list

From Dev

Retrieve info from Kafka that has a field matching one value of a very long list

From Dev

QML - How to retrieve info from a text edit inside a list view

From Dev

DB Design: additional info for many to many field

From Dev

WooCommerce: Get custom field from product variations and display it on the "additional information area"

From Dev

Cakephp retrieve info from database

From Dev

Woocommerce Additional Information Tab: Adding product custom field value

From Dev

passing product info from one view to another

From Dev

retrieve useful info from webpage using JSOUP

From Dev

WPF retrieve leap info from different class

From Dev

Retrieve Info From Callback Thread Safe Implementation

From Dev

retrieve useful info from webpage using JSOUP

From Dev

Retrieve values from a List

From Dev

Retrieve values from LIST<>

From Dev

Stripe with Django - Retrieve product / price from Session

From Dev

Retrieve Product's Top Category from Magento

From Dev

Retrieve Windows 8 Product Key from mainboard

From Dev

Retrieve a json field from mysql field with PDO

From Dev

Getting Additional Field From Different Table

From Dev

Select Additional Field from another Table

From Dev

Retrieve a list B from a list A

From Dev

Additional info from MDC to logs (java.util.logging)

From Dev

Retrieve an object field from a list of items with one map-filter lambda expression

From Dev

Jira: how to retrieve a list of field configurations for a project

From Dev

Jira: how to retrieve a list of field configurations for a project

From Dev

Retrieve extra info from one option from autocomplete

From Dev

Retrieve extra info from one option from autocomplete

From Dev

Associating Additional Info in DropDown

From Dev

XCode intellisense with additional info

Related Related

  1. 1

    Retrieve info from additional field to product list

  2. 2

    Retrieve info from Kafka that has a field matching one value of a very long list

  3. 3

    QML - How to retrieve info from a text edit inside a list view

  4. 4

    DB Design: additional info for many to many field

  5. 5

    WooCommerce: Get custom field from product variations and display it on the "additional information area"

  6. 6

    Cakephp retrieve info from database

  7. 7

    Woocommerce Additional Information Tab: Adding product custom field value

  8. 8

    passing product info from one view to another

  9. 9

    retrieve useful info from webpage using JSOUP

  10. 10

    WPF retrieve leap info from different class

  11. 11

    Retrieve Info From Callback Thread Safe Implementation

  12. 12

    retrieve useful info from webpage using JSOUP

  13. 13

    Retrieve values from a List

  14. 14

    Retrieve values from LIST<>

  15. 15

    Stripe with Django - Retrieve product / price from Session

  16. 16

    Retrieve Product's Top Category from Magento

  17. 17

    Retrieve Windows 8 Product Key from mainboard

  18. 18

    Retrieve a json field from mysql field with PDO

  19. 19

    Getting Additional Field From Different Table

  20. 20

    Select Additional Field from another Table

  21. 21

    Retrieve a list B from a list A

  22. 22

    Additional info from MDC to logs (java.util.logging)

  23. 23

    Retrieve an object field from a list of items with one map-filter lambda expression

  24. 24

    Jira: how to retrieve a list of field configurations for a project

  25. 25

    Jira: how to retrieve a list of field configurations for a project

  26. 26

    Retrieve extra info from one option from autocomplete

  27. 27

    Retrieve extra info from one option from autocomplete

  28. 28

    Associating Additional Info in DropDown

  29. 29

    XCode intellisense with additional info

HotTag

Archive