Question

I've Override code for manufacturers to have extra fields in the controller and in the classes , also created the database columns and all the info is being stored without any problem, the issue comes when I tried to pull the information back. I've add 4 variables but im only able to pull from 2 of them /** @var string Region */ public $laregion;

/** @var string address */
public $ladireccion;

/** @var string website */
public $website;

/** @var string Is from quebec? */
public $quebec;

I define the variables there and set the array as follow:

    public static $definition = array(
    'table' => 'manufacturer',
    'primary' => 'id_manufacturer',
    'multilang' => true,
    'fields' => array(
    'name' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
        'website' =>            array('type' => self::TYPE_STRING, 'validate' => 'isUrl', 'required' => true, 'size' => 64),
        'quebec' =>             array('type' => self::TYPE_BOOL),
        'active' =>             array('type' => self::TYPE_BOOL),
        'date_add' =>           array('type' => self::TYPE_DATE),
        'date_upd' =>           array('type' => self::TYPE_DATE),

        // Lang fields
        'laregion' =>           array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 255),
        'ladireccion' =>        array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 255),
        'description' =>        array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
        'short_description' =>  array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
        'meta_title' =>         array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
        'meta_description' =>   array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
        'meta_keywords' =>      array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'),
    ),
);

but when I want to get the info from laregion or ladireccion I get nothing is not even on the debug but other 2 are..

    >value = Array (1)
0 => Array (12)
id_manufacturer => "5"
name => "test test"
date_add => "2014-04-16 15:20:04"
date_upd => "2014-04-16 16:19:36"
active => "1"
website => "website.com"
quebec => "0"
description => "<p>test french</p>"
short_description => "<p>test french</p>"
nb_products => "0"
link_rewrite => 0
image => "fr-default"
->nocache = false

You can see that website and quebec are there but not the multiplelanguage elements, Some one have an Idea why this happen?

Thank you

Was it helpful?

Solution

I found the solution you have to set the variables on the getmanufacturers

public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false)
{
    if (!$id_lang)
        $id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
    if (!Group::isFeatureActive())
        $all_group = true;

    $manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
    SELECT m.*, ml.`description`, ml.`short_description`, ml.`laregion`,ml.`ladireccion`
    FROM `'._DB_PREFIX_.'manufacturer` m
    '.Shop::addSqlAssociation('manufacturer', 'm').'
    INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
    '.($active ? 'WHERE m.`active` = 1' : '').'
    ORDER BY m.`name` ASC
    '.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
    if ($manufacturers === false)
        return false;

    if ($get_nb_products)
    {
        $sql_groups = '';
        if (!$all_group)
        {
            $groups = FrontController::getCurrentCustomerGroups();
            $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
        }

        foreach ($manufacturers as $key => $manufacturer)
        {
            $manufacturers[$key]['nb_products'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
            SELECT COUNT(DISTINCT p.`id_product`)
            FROM `'._DB_PREFIX_.'product` p
            '.Shop::addSqlAssociation('product', 'p').'
            WHERE p.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].'
            AND product_shop.`visibility` NOT IN ("none")
            '.($active ? ' AND product_shop.`active` = 1 ' : '').'
            '.($all_group ? '' : ' AND p.`id_product` IN (
                SELECT cp.`id_product`
                FROM `'._DB_PREFIX_.'category_group` cg
                LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
                WHERE cg.`id_group` '.$sql_groups.'
            )'));
        }
    }

    $total_manufacturers = count($manufacturers);
    $rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
    for ($i = 0; $i < $total_manufacturers; $i++)
        $manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
    return $manufacturers;
}

you can see it does a select for everything on m. and specifics on ml. ml is the one where all the Manufacturers_Lang is stored.. so thats why the other 2 were there...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top