Jump to content

list of products


feof84

Recommended Posts

Hi,

I would like to create a page that shows a list of products with a specific reference field.

 

of course I have to do a select in the database to rewash the products with a specific field, but I have no idea how to view the output in my page.

 

 

In this case I have no idea how to view the output of the product list, in practice must be the same output as when you open a category, a list of products.

 

 

I think there is already a template prepared for the output of a category, as I use it?

 

Give me a hand?

 

thank you!

Link to comment
Share on other sites

Hi,

I would like to create a page that shows a list of products with a specific reference field.

 

of course I have to do a select in the database to rewash the products with a specific field, but I have no idea how to view the output in my page.

 

 

In this case I have no idea how to view the output of the product list, in practice must be the same output as when you open a category, a list of products.

 

 

I think there is already a template prepared for the output of a category, as I use it?

 

Give me a hand?

 

thank you!

 

You've got php code that select from database correct rows (exactly as you want) ?

 

Check category class, you find there function for selecting products with specification from database

 

 

public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true)

{

...

}

 

compare returned array from this function with category.tpl file from your template.

 

You can also use print_r($array) to show array structure and you can foreach it by own script

Link to comment
Share on other sites

You've got php code that select from database correct rows (exactly as you want) ?

 

 

hello,

thanks for the reply.

 

Do you have a document that explains how to use GetProdutcs?

 

I'm having some difficulty understanding how to use it

Link to comment
Share on other sites

hello,

thanks for the reply.

 

Do you have a document that explains how to use GetProdutcs?

 

I'm having some difficulty understanding how to use it

 

 

 

Hello,

I say alone.

 

 

$ product_list = Product :: getProducts ($ cookie-> id_lang, 0,0, 'id_product', 'ASC', 60, true);

print_r ($ product_list);

 

 

So actually I see the products, but I have to tie them to category.tpl, like you said you now try to understand.

Link to comment
Share on other sites

Hello,

I say alone.

 

 

$ product_list = Product :: getProducts ($ cookie-> id_lang, 0,0, 'id_product', 'ASC', 60, true);

print_r ($ product_list);

 

 

So actually I see the products, but I have to tie them to category.tpl, like you said you now try to understand.

 

 

ok, so now: what you exactly want to do with products? You want to write own module? Or maybe you want to edit the product listing in categories?

Link to comment
Share on other sites

ok, so now: what you exactly want to do with products? You want to write own module? Or maybe you want to edit the product listing in categories?

 

 

I'm already writing a module. The products "user-created" have a specific range (supplier_reference) that contains the id of the user who created the product. I wish that when you click on the avatar of the user (http://www.mytshirt.name/mytshirt/wizardshirt/community.php) this face to see the list of products created using that particular field.

 

The output will be identical to that of a category.

 

The category contains products created by users is always the same, with id 60.

 

Do you understand?

Link to comment
Share on other sites

I'm already writing a module. The products "user-created" have a specific range (supplier_reference) that contains the id of the user who created the product. I wish that when you click on the avatar of the user (http://www.mytshirt....t/community.php) this face to see the list of products created using that particular field.

 

The output will be identical to that of a category.

 

The category contains products created by users is always the same, with id 60.

 

Do you understand?

 

 

ok, now it's clear :)

So, you've got in products array field with user id? can you print_r some part of array here? I will write foreach for it

Link to comment
Share on other sites

ok, now it's clear :)

So, you've got in products array field with user id? can you print_r some part of array here? I will write foreach for it

 

 

 

$product_list = Product::getProducts($cookie->id_lang, 0,0, 'id_product', 'ASC', 60, true);

print_r($product_list);

 

 

Welcome to my shop! cane to patri Array ( [0] => Array ( [id_product] => 816 [id_supplier] => 0 [id_manufacturer] => 0 [id_tax_rules_group] => 0 [id_category_default] => 60 [id_color_default] => 0 [on_sale] => 0 [online_only] => 0 [ean13] => [upc] => [ecotax] => 0.000000 [quantity] => 3520 [minimal_quantity] => 1 [price] => 11.590000 [wholesale_price] => 0.000000 [unity] => [unit_price_ratio] => 0.000000 [additional_shipping_cost] => 0.00 [reference] => reference [supplier_reference] => 72 [location] => [width] => 0 [height] => 0 [depth] => 0 [weight] => 0 [out_of_stock] => 2 [quantity_discount] => 0 [customizable] => 0 [uploadable_files] => 0 [text_fields] => 0 [active] => 1 [available_for_order] => 1 [condition] => new [show_price] => 1 [indexed] => 1 [cache_is_pack] => 0 [cache_has_attachments] => 0 [cache_default_attribute] => 72774 [date_add] => 0000-00-00 00:00:00 [date_upd] => 2012-08-18 13:57:42 [id_lang] => 5 [description] =>

Apri il tuo armadio e ti sembra di non avere mai il capo giusto? Con questa maglia non avrai più problemi, glamour con un tocco di vivacità, un capo unico, proprio come te.

[description_short] =>

Un tocco di romanticismo glam per la tua estate 2012

[link_rewrite] => your-t-shirt [meta_description] => t-shirt Sweet ribbon [meta_keywords] => t-shirt,tshirt,sweet ribbon,romanticismo,romatica,cinta,estate [meta_title] => t-shirt Sweet ribbon [name] => Sweet ribbon [available_now] => [available_later] => [tax_rate] => [manufacturer_name] => [supplier_name] => ) [1] => Array ( [id_product] => 820 [id_supplier] => 0 [id_manufacturer] => 0 [id_tax_rules_group] => 0 [id_category_default] => 60 [id_color_default] => 0 [on_sale] => 0 [online_only] => 0 [ean13] => [upc] => [ecotax] => 0.000000 [quantity] => 3520 [minimal_quantity] => 1 [price] => 9.590000 [wholesale_price] => 0.000000 [unity] => [unit_price_ratio] => 0.000000 [additional_shipping_cost] => 0.00 [reference] => reference [supplier_reference] => 82 [location] => [width] => 0 [height] => 0 [depth] => 0 [weight] => 0 [out_of_stock] => 2 [quantity_discount] => 0 [customizable] => 0 [uploadable_files] => 0 [text_fields] => 0 [active] => 1 [available_for_order] => 1 [condition] => new [show_price] => 1 [indexed] => 1 [cache_is_pack] => 0 [cache_has_attachments] => 0 [cache_default_attribute] => 68550 [date_add] => 0000-00-00 00:00:00 [date_upd] => 2012-08-18 13:59:45 [id_lang] => 5 [description] => [description_short] =>

"Mani che sfiorano il suono della vita." Ignazio Gagliano

[link_rewrite] => your-t-shirt [meta_description] => t-shirt mani che sfiorano il suono della vita [meta_keywords] => t-shirt,tshirt,mani,chitarra,suono,musica,vita [meta_title] => t-shirt mani chitarra [name] => Mani e Chitarra [available_now] => [available_later] => [tax_rate] => [manufacturer_name] => [supplier_name] => ) )

 

 

 

[supplier_reference] is on the field that identifies the user who created the product

Link to comment
Share on other sites

this is code for foreach $products array used in products_list.tpl template:

 

 

{foreach from=$products item=product name=products}

{if $product.supplier_reference == "$_GET['USERIDVARHERE']}

<li class="ajax_block_product {if $smarty.foreach.products.first}first_item{elseif $smarty.foreach.products.last}last_item{/if} {if $smarty.foreach.products.index % 2}alternate_item{else}item{/if} clearfix">

<div class="center_block">

<a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" title="{$product.name|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} /></a>

<h3>{if isset($product.new) && $product.new == 1}<span class="new">{l s='New'}</span>{/if}<a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></h3>

<p class="product_desc"><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.description_short|truncate:360:'...'|strip_tags:'UTF-8'|escape:'htmlall':'UTF-8'}">{$product.description_short|truncate:360:'...'|strip_tags:'UTF-8'}</a></p>

</div>

<div class="right_block">

{if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}<span class="on_sale">{l s='On sale!'}</span>

{elseif isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}<span class="discount">{l s='Reduced price!'}</span>{/if}

{if isset($product.online_only) && $product.online_only}<span class="online_only">{l s='Online only!'}</span>{/if}

{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}

<div>

{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span><br />{/if}

{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}<span class="availability">{if ($product.allow_oosp || $product.quantity > 0)}{l s='Available'}{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}{l s='Product available with different options'}{else}{l s='Out of stock'}{/if}</span>{/if}

</div>

{/if}

{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity <= 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}

{if ($product.allow_oosp || $product.quantity > 0)}

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>

{else}

<span class="exclusive">{l s='Add to cart'}</span>

{/if}

{/if}

<a class="button" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a>

{if isset($comparator_max_item) && $comparator_max_item}

<p class="compare"><input type="checkbox" class="comparator" id="comparator_item_{$product.id_product}" value="comparator_item_{$product.id_product}" {if isset($compareProducts) && in_array($product.id_product, $compareProducts)}checked{/if}/> <label for="comparator_item_{$product.id_product}">{l s='Select to compare'}</label></p>

{/if}

</div>

</li>

{/if}

{/foreach}

 

I did some modifications for it.

You must add a {if} condition (orange color) which checks the user id. from url parameter ?USERIDVARHERE=12

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

hello, thank you for your help.

Your code is to be entered in a tpl file, but how do I switch? USERIDVARHERE the tpl file?

 

 

<?php

global $smarty;

include('../../config/config.inc.php');

include('../../header.php');

 

 

$product_list = Product::getProducts($cookie->id_lang, 0,0, 'id_product', 'ASC', 60, true);

$smarty->display(dirname(__FILE__).'/mymodule_page.tpl');

 

include('../../footer.php');

?>

 

your code is inserted into mymodule_page.tpl but how I make them interact?

Link to comment
Share on other sites

hello, thank you for your help.

Your code is to be entered in a tpl file, but how do I switch? USERIDVARHERE the tpl file?

 

 

<?php

global $smarty;

include('../../config/config.inc.php');

include('../../header.php');

 

 

$product_list = Product::getProducts($cookie->id_lang, 0,0, 'id_product', 'ASC', 60, true);

$smarty->display(dirname(__FILE__).'/mymodule_page.tpl');

 

include('../../footer.php');

?>

 

your code is inserted into mymodule_page.tpl but how I make them interact?

 

you must create a smarty global variable with products array variable

 

 

$product_list = Product::getProducts($cookie->id_lang, 0,0, 'id_product', 'ASC', 60, true);

$smarty->assign('products', $product_list );

$smarty->display(dirname(__FILE__).'/mymodule_page.tpl');

 

now you can use $products variable in your mymodule_page.tpl

 

Maybe the code for foreach doesn't work properly, but it's not a problem - we can solve it here if you paste error log ;)

So, try it ;)

Link to comment
Share on other sites

hello,

I can not display anything, apache logs tell me:

 

[Wed Sep 26 14:37:05 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: withBlockLeft in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

[Wed Sep 26 14:37:05 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: withBlockLeft in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

[Wed Sep 26 14:37:06 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: _GET in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

[Wed Sep 26 14:37:06 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: _GET in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

[Wed Sep 26 14:37:06 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: withBlockRight in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

[Wed Sep 26 14:37:06 2012] [error] [client 127.0.0.1] PHP Notice: Undefined variable: withBlockRight in / var / www / mytshirt / tools / smarty / sysplugins / smarty_internal_data.php on line 291

 

The module consists of the file:

 

cat mymodule_page.php

 

<? Php

global $ smarty;

include ('.. /.. / config / config.inc.php');

include ('.. /.. / header.php');

 

/ / $ Smarty-> display (dirname (__FILE__). '/ Mymodule_page.tpl');

/ / $ Smarty-> assign ('messageSmarty', "to shareholders"); / / creation of our variable

/ / $ Smarty-> display (dirname (__FILE__). '/ Mymodule_page2.tpl');

 

$ Product_list = Product :: getProducts ($ cookie-> id_lang, 0,0, 'id_product', 'ASC', 60, true);

 

$ Smarty-> assign ('products', $ product_list);

$ Smarty-> display (dirname (__FILE__). '/ Mymodule_page.tpl');

 

 

 

include ('.. /.. / footer.php');

?>

 

cat mymodule_page.tpl

{Foreach from = $ products item = product name = products}

{If $ product.supplier_reference == "$ _GET ['USERIDVARHERE']"}

<Li class = "{if $ ajax_block_product smarty.foreach.products.first first_item} {elseif $ smarty.foreach.products.last last_item} {/ if} {if $ smarty.foreach.products.index% 2} {else alternate_item item} {/ if} clearfix ">

<div class="center_block">

<A href = "{$ product.link | escape: 'htmlall': 'UTF-8'}" class = "product_img_link" title = "{$ product.name | escape: 'htmlall': 'UTF-8'} "> <img src="{$link-> getImageLink ($ product.link_rewrite, $ product.id_image, 'home')}" alt = "{$ product.legend | escape: 'htmlall': 'UTF-8' } "{if isset ($ homeSize)} width =" {$} homeSize.width "height =" {$ homeSize.height} "{/ if} /> </ a>

<h3> {if isset ($ product.new) && $ product.new == 1} {ls = <span class="new"> 'New'} </ span> {/ if} <a href = "{ $ product.link | escape: 'htmlall': 'UTF-8'} "

<p class="product_desc"> <a href = "{$ product.link | escape: 'htmlall': 'UTF-8'}"

</ Div>

<div class="right_block">

{If isset ($ product.on_sale) && $ product.on_sale && isset ($ product.show_price) && $ product.show_price &&! $ PS_CATALOG_MODE <span class="on_sale">} {ls = 'On sale!'} < / span>

{Elseif isset ($ product.reduction) && $ product.reduction && isset ($ product.show_price) && $ product.show_price &&! $ PS_CATALOG_MODE <span class="discount">} {ls = 'Reduced price!'} < / span> {/ if}

{If isset ($ product.online_only) && $ product.online_only <span class="online_only">} {ls = 'Online only!'} </ Span> {/ if}

{If ($ PS_CATALOG_MODE AND ((isset ($ product.show_price) && $ product.show_price) | | (isset ($ product.available_for_order) && $ product.available_for_order)))}

<div>

{If isset ($ product.show_price) && $ product.show_price &&! Isset ($ restricted_country_mode)} <span style="display: class="price" inline;"> {if! PriceDisplay} {$ price = $ product convertPrice . price} {else} {convertPrice price = $ product.price_tax_exc} {/ if} </ span> /> {/ if}

{If isset ($ product.available_for_order) && $ product.available_for_order &&! Isset ($ restricted_country_mode)} <span class="availability"> {if ($ product.allow_oosp | | $ product.quantity> 0)} {ls = 'Available'} {elseif (isset ($ product.quantity_all_versions) && $ product.quantity_all_versions> 0)} {ls = 'Product available with different options'} {else} {ls = 'Out of stock'} {/ if} </ span> {/ if}

</ Div>

{/ If}

{If ($ product.id_product_attribute == 0 | | (isset ($ add_prod_display) && ($ add_prod_display == 1))) && $ product.available_for_order &&! Isset ($ restricted_country_mode) && $ product.minimal_quantity <= 1 && $ product.customizable! = 2 &&! $ PS_CATALOG_MODE}

{If ($ product.allow_oosp | | $ product.quantity> 0)}

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link-> getPageLink ('cart.php')}? add & id_product = {$ product.id_product | intval} {if isset ($ static_token)} & token = {$ static_token} {/ if} "title =" {ls = 'Add to cart'} "> {ls = 'Add to cart'} </ a>

{Else}

<span class="exclusive"> {ls = 'Add to cart'} </ span>

{/ If}

{/ If}

<a class="button" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{ls='View'}"> {ls = 'View'} </ to>

{If isset ($ comparator_max_item) && $ comparator_max_item}

<p class="compare"> <input type = "checkbox" class = "comparator" id = "{$ comparator_item_ product.id_product}" value = "$ {comparator_item_ product.id_product}" {if isset ($ CompareProducts) && in_array ($ product.id_product, $ CompareProducts)} checked {/ if} /> <label for="comparator_item_{$product.id_product}"> {ls = 'Select to compare'} </ label> </ p>

{/ If}

</ Div>

</ Li>

{/ If}

{/ Foreach}

Link to comment
Share on other sites

mymodule_page.php is your main module file?

 

hmmm for first: change the $Smarty value to string with lower letters: $smarty

 

you've got empty char between $<here>Smarty ?

 

are in lower letters.

No, is the web editor I change the output

:-( :-(

Link to comment
Share on other sites

  • 3 weeks later...

Hi Vekia,

 

I thank you for your precious help.

I edited the php file like this:

 

 

if ($n == 0)

$n = 10;

$category = new Category(60);

$productsViewed = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, false, true, false, 0, true);

$nbProducts = sizeof($productsViewed);

include('../../pagination.php');

$smarty->assign(array(

'products' => $productsViewed,

'nbProducts' => $nbProducts));

 

 

The problem is that in the tpl file you suggested, similar to product_list.php I do not see all the products in the category 60 because after 10 products included in the category with id 60, the tpl file shows me the products that are in the range between 1 and 10.

 

How can I solve the problem?

 

For example, this user has 2 tshirt created, but I can see only one because it is in the range of the first 10 tshirt http://www.mytshirt.name/mytshirt/modules/mymodule/mymodule_page.php?iduser=3

 

Help me please ?

Link to comment
Share on other sites

  • 3 months later...

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...