Jump to content

Where product-list.tpl variables are produced and assigned


Recommended Posts

Hi There, 

I am newbie in ps module programming, built a little module and would lie to use the existing template. 

My problem is that those variables are needed for these template are not generated. Where are these variables are generated and assigned to the tpl? In which controller or which functions can be used for that. 

for example the $product.availability, $product.quantity, $product.availability_message and so on...

Sorry for the silly question. 

 

 

Link to comment
Share on other sites

1 hour ago, endriu107 said:

In your module controller add:

$id_product = Tools::getValue('id_product');
$product = new Product($id_product, $context->language->id);

THank you endriu!

I did and I have got the following $product array members in my tpl. $product.availability, $product.availability_message are still not available. 

Array (2)
value => Product Object (82)
   ->tax_name = null
   ->tax_rate = null
   ->id_manufacturer = "0"
   ->id_supplier = "0"
   ->id_category_default = "19"
   ->id_shop_default = "1"
   ->manufacturer_name = null
   ->supplier_name = null
   ->name = "GLP GPV-75-12 12V 75W LED DRIVER/POWE..."
   ->description = "<ul style="list-style-type:disc;"> <l..."
   ->description_short = "<p style="text-align:left;"><strong>G..."
   ->quantity = "0"
   ->minimal_quantity = "1"
   ->low_stock_threshold = null
   ->low_stock_alert = "0"
   ->available_now = ""
   ->available_later = ""
   ->price = "15.770000"
   ->specificPrice = 0
   ->additional_shipping_cost = "0.000000"
   ->wholesale_price = "3.330000"
   ->on_sale = "0"
   ->online_only = "0"
   ->unity = "Per Unit"
   ->unit_price = 0
   ->unit_price_ratio = "0.000000"
   ->ecotax = "0.000000"
   ->reference = "GPV-75-12"
   ->supplier_reference = ""
   ->location = ""
   ->width = "0.000000"
   ->height = "0.000000"
   ->depth = "0.000000"
   ->weight = "0.000000"
   ->ean13 = ""
   ->isbn = ""
   ->upc = ""
   ->mpn = ""
   ->link_rewrite = "glp-gpv-75-12-12v-75w-led-driverpower..."
   ->meta_description = "Global Lead Power GPV-75-12 12V 75Wat..."
   ->meta_keywords = ""
   ->meta_title = "GPV-75-12 12V 75W LED DRIVER / POWER ..."
   ->quantity_discount = "0"
   ->customizable = "0"
   ->new = null
   ->uploadable_files = "0"
   ->text_fields = "0"
   ->active = "1"
   ->redirect_type = "404"
   ->id_type_redirected = "0"
   ->available_for_order = "1"
   ->available_date = "0000-00-00"
   ->show_condition = "0"
   ->condition = "new"
   ->show_price = "1"
   ->indexed = "1"
   ->visibility = "both"
   ->date_add = "2021-09-26 19:49:37"
   ->date_upd = "2022-01-01 16:38:17"
   ->tags = null
   ->state = "1"
   ->base_price = null
   ->id_tax_rules_group = "12"
   ->id_color_default = 0
   ->advanced_stock_management = "0"
   ->out_of_stock = "2"
   ->depends_on_stock = null
   ->isFullyLoaded = false
   ->cache_is_pack = "0"
   ->cache_has_attachments = "0"
   ->is_virtual = "0"
   ->id_pack_product_attribute = null
   ->cache_default_attribute = "0"
   ->category = "led-drivers-power-supplies"
   ->pack_stock_type = "3"
   ->additional_delivery_times = "1"
   ->delivery_in_stock = ""
   ->delivery_out_stock = ""
   ->product_type = "standard"
   ->id = 471
   ->id_shop_list = Array (0)
   ->force_id = false
scope => "Smarty object"

 

Link to comment
Share on other sites

{$product->jsonSerialize()|dump} is does not work in my template file. Freezing. 

However if I see with {debug} the $product array object is there with 97 items. None of them are $product.availability or $product.availability_message.

I do not know where these are generated. Templates use even $product.url . I do not have them. 

 

Link to comment
Share on other sites

I think I am doing wrong something

In my controller I do this and assign it at the end. I use ajax call and fetch the template with the assigned variables. 

$id_category=48;
$category = new Category($id_category);
$productok = $category->getProducts($lang_id, 0, 1000, 'id_product', 'asc');

$products = Product::getProductsProperties($this->context->language->id,$productok);
$product= $products[0];


$this->context->smarty->assign(
            array(
                'sajatmulti'=>$multi,
                'test1'=> $szamlalo1,
                'test2'=> $szamlalo2,
                'test3'=> $szamlalo3,
                'masolat'=>$multi2,
                'kakukk'=>$kakukk,
                'product'=>$product

            ));

die($this->context->smarty->fetch(_PS_MODULE_DIR_.'proba/views/templates/front/ajax.tpl'));

When I put  {$product->jsonSerialize()|dump} to my template, it is freezing.

When I put to my normal template file for in partials/product-list  it works. With normal debug I cannot see, but using your json dump it can be found.

What am I missing?

Link to comment
Share on other sites

14 minutes ago, endriu107 said:

In your code I don't see code I post before, and this code you share is incomplete, I didn't have time to guess what you have or haven't. I think you should look at the ps_featuredproducts modules.

Good luck

 

Here is the full code of controller called by the Request data button:

 

<?php

class probaFcont2ModuleFrontController extends ModuleFrontController
{

 public function __construct()
  {
    parent::__construct();
  }


public function initContent()
{

$this->ajax = true;
parent::initContent();

}

  public function displayAjax()

    {
	$valtozo = Tools::getValue('method');
	$hossztxt = Tools::getValue('hossz');
	$hossz = (float)$hossztxt;
	$hossz = $hossz*2;
	
	$this->context->smarty->assign(array(
        'ujhossz' => $hossz)
    );


$link = new Link;//because getImageLInk is not static function
$feszultseg=12;
$multi=array('0' => array('reference'=>'name1', 'power'=>12, 'link'=>'link12'));
$multi2=array('0' => array('reference'=>'name1', 'power'=>12, 'link'=>'link12'));
unset($multi['0']);
unset($multi2['0']);

function cmp($a, $b) {
    if($a['power'] == $b['power']) {
        return 0;
    }
    return ($a['power'] < $b['power']) ? -1 : 1;
}

$productId="47";

$lang_id = (int) Configuration::get('PS_LANG_DEFAULT');
$product = new Product($productId, $lang_id); // get product object with id
$name    = $product->id_category_default;
//var_dump($productData);


//$Product::getProductsProperties((int)$id_lang, $result);


//$categories = $productData->getCategories();
//var_dump($categories);

$product_features = $product->getfeatures();
$prfeatures = $product->getFrontFeatures($this->context->language->id);
$nev="meg nem tudom";
$szamlalo1=0;
$szamlalo2=0;
$szamlalo3=0;
//var_dump($prfeatures);



//ITT MOST A GPV POWER TAPOKAT GYUJTOM LE ES KIIRATOM A NEVUKET
$id_category=48;
$category = new Category($id_category);
$productok = $category->getProducts($lang_id, 0, 1000, 'id_product', 'asc');

$products = Product::getProductsProperties($this->context->language->id,$productok);
$product= $products[0];



//valojaban ezt kapom a getProducts al

$szamiszami=0;  //szamlalo a multi2 masolathoz ami valojaban a productok roviditett valtozata
$kakukk=0;

foreach ($productok as $termek) {

    if((int)trim($termek[features][1][value],"V")==$feszultseg)
    {
        $szam=(int)trim(trim($termek[features][3][value],"W/m"),"W");

        if($szam > 75) {

            $kakukk++;
            $productData = new Product($termek["id_product"], false, $lang_id); // get product object with id
            $cover = Product::getCover($productData->id);
            $kepPath = $link->getImageLink($productData->link_rewrite, $image['id_image'], 't');

            $multi[$productData->id]=array(

                'name'=>$productData->name,
                'reference'=>$productData->reference,
                'netprice'=>$productData->price,
                'price'=>$termek['price'],
                'price_no_tax'=>$termek['price_tax_exc'],
                'power'=>$szam,
                'link'=>$productData->link_rewrite,
                'quantity'=>Product::getQuantity($productData->id, 0),
                'cover' =>$cover,
                'imgPath'=>$kepPath,
                'power2'=>$termek[features][3][value]


            );
            $multi2[$szamiszami]=$termek;
            $szamiszami++;
                }

    }

//$azonosito=$termek["id_product"];
$productData = new Product($termek["id_product"], false, $lang_id); // get product object with id
$prfeatures = $productData->getFrontFeatures($this->context->language->id);
//$product_price = $productData->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC);

}

//tomb sorbarakasa es kiiratasa ************start
uasort($multi,cmp);


//tomb sorbarakasa es kiiratasa *************vege

$this->context->smarty->assign(
            array(
                'sajatmulti'=>$multi,
                'test1'=> $szamlalo1,
                'test2'=> $szamlalo2,
                'test3'=> $szamlalo3,
                'masolat'=>$multi2,
                'kakukk'=>$kakukk,
                'product'=>$product

            ));

//this is a copy of themes/default/product-list.tpl
//$this->setTemplate("catalog/_partials/listing/product-list.tpl");
//die(Tools::jsonEncode(array('result' => $valtozo)));
die($this->context->smarty->fetch(_PS_MODULE_DIR_.'proba/views/templates/front/ajax.tpl'));

    }


}


?>

 

I checked the ps_featuredproducts modules , but could not figure out how that could help.

My template does not get the full data and I do not know how to produce that. 

My code contains a lot of experiments, this is why I did not put the entire before.

I am looking for how to give to the template the full product data which includes all of the data needed for the templates.

 

Edited by NemTom66 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Here in your code you want to get all products from specific category:

$id_category=48;
$category = new Category($id_category);
$productok = $category->getProducts($lang_id, 0, 1000, 'id_product', 'asc');

$products = Product::getProductsProperties($this->context->language->id,$productok);
$product= $products[0];

same thing is in ps_featuredproducts module there is getProducts() method and those products should contains all data you need.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

 

On 1/3/2022 at 2:39 PM, NemTom66 said:

Hi There, 

I am newbie in ps module programming, built a little module and would lie to use the existing template. 

My problem is that those variables are needed for these template are not generated. Where are these variables are generated and assigned to the tpl? In which controller or which functions can be used for that. 

for example the $product.availability, $product.quantity, $product.availability_message and so on...

Sorry for the silly question. 

 

 

Not sure if it's what you're looking for, but when you instance Product class, you can turn "$full" to true, to get ALL the variables inside the Product object.

$productData = new Product($termek["id_product"], true, $lang_id); --> Assign true to retrieve all Product variables inside the class.

 

 

 

Link to comment
Share on other sites

Thanks for all. I was looking for the lazy array in order to use the data in a child template with simple extending the main template.

At the end I found the solution by using the ProductAssembler and ProductListingPresenter to produce the Lazy array for selected products ids stored in an array. 

 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...