Jump to content

[solved] Adding a supplier to product


Recommended Posts

it's possible, but modification of the core files is necessary.

What prestashop version you use? It's important question in this case.

Give me info about your PS version and i will show you how easily add supplier info to product page

Link to comment
Share on other sites

okay

 

thanks

 

so open the productController.php file located in your controllers/front/ directory

near the 245 line you've got something like:

 

$this->context->smarty->assign(array(
   'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
   'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false,
...

 

add there:

'supplier' => new Supplier($this->product->id_supplier,$this->context->language->id),

 

code should looks like:

 

$this->context->smarty->assign(array(
		    'supplier' => new Supplier($this->product->id_supplier,$this->context->language->id),
   'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
   'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false,
...

 

 

then in product.tpl file you can use {$supplier} variable as an object, for example:

 

description: {$supplier->description}

name: {$supplier->name}

Link to comment
Share on other sites

It´s any like this:

 

Supplier Object ( [id] => 2 [id_supplier] => 2 [name] => Shure Online Store [description] => [date_add] => 2013-04-01 19:10:12 [date_upd] => 2013-04-01 19:10:12 [link_rewrite] => shure-online-store [meta_title] => [meta_keywords] => [meta_description] => [active] => 1 [webserviceParameters:protected] => Array ( [fields] => Array ( [link_rewrite] => Array ( [sqlId] => link_rewrite ) ) ) [id_lang:protected] => 5 [id_shop:protected] => 1 [id_shop_list] => [get_shop_from_context:protected] => 1 [table:protected] => supplier [identifier:protected] => id_supplier [fieldsRequired:protected] => Array ( [0] => name ) [fieldsSize:protected] => Array ( [name] => 64 ) [fieldsValidate:protected] => Array ( [name] => isCatalogName [date_add] => isDate [date_upd] => isDate ) [fieldsRequiredLang:protected] => Array ( ) [fieldsSizeLang:protected] => Array ( [meta_title] => 128 [meta_description] => 255 [meta_keywords] => 255 ) [fieldsValidateLang:protected] => Array ( [description] => isGenericName [meta_title] => isGenericName [meta_description] => isGenericName [meta_keywords] => isGenericName ) [tables:protected] => Array ( ) [image_dir:protected] => /www/k/o/u20747/public_html/_sub/prestashop/img/su/ [image_format:protected] => jpg [def:protected] => Array ( [table] => supplier [primary] => id_supplier [multilang] => 1 [fields] => Array ( [name] => Array ( [type] => 3 [validate] => isCatalogName [required] => 1 [size] => 64 ) [active] => Array ( [type] => 2 ) [date_add] => Array ( [type] => 5 [validate] => isDate ) [date_upd] => Array ( [type] => 5 [validate] => isDate ) [description] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName ) [meta_title] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName [size] => 128 ) [meta_description] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName [size] => 255 ) [meta_keywords] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName [size] => 255 ) ) [classname] => Supplier [associations] => Array ( [l] => Array ( [type] => 2 [field] => id_supplier [foreign_field] => id_supplier ) ) ) [update_fields:protected] => ) 1

 

But I need only contact info - adress, phone, e-mail...

Link to comment
Share on other sites

if you set all value in description of supplier than you can use like this variable

{$Supplier->description}

and get supplier description .

 

but he said that he want email address - full contact info..

Link to comment
Share on other sites

okay! i've got it ! :)

 

use this:

$address_id=Address::getAddressIdBySupplierId($this->product->id_supplier);
$this->context->smarty->assign(array(
      'supplier' => new Address($address_id),

 

instead the modification code that i pasted before:

$this->context->smarty->assign(array(
    'supplier' => new Supplier($this->product->id_supplier,$this->context->language->id),

 

 

effect:

 

[id_customer] => 0
   [id_manufacturer] => 0
   [id_supplier] => 1
   [id_warehouse] => 0
   [id_country] => 21
   [id_state] => 32
   [country] => United States
   [alias] => supplier
   [company] => Apple
   [lastname] => supplier
   [firstname] => supplier
   [address1] => 767 Fifth Ave.
   [address2] =>
   [postcode] => 10153
   [city] => New York
   [other] =>
   [phone] => (212) 336-1440
   [phone_mobile] =>
   [vat_number] =>
   [dni] =>
   [date_add] => 2013-05-25 14:31:36
   [date_upd] => 2013-05-25 14:31:36
   [deleted] => 0

 

array with contact informations

Link to comment
Share on other sites

(...) so open the productController.php file located in your controllers/front/ directory

near the 245 line...

 

$address_id=Address::getAddressIdBySupplierId($this->product->id_supplier);
$this->context->smarty->assign(array(
   'supplier' => new Address($address_id),

 

 

then in product.tpl you will be able to use {$supplier} variable:

 

{$supplier->company}

{$supplier->address1}

{$supplier->address2}

 

{$supplier->phone}

 

and other variables from array that i pasted above

Link to comment
Share on other sites

Well, but in product apears only {$supplier->postcode}, {$supplier->city} and {$supplier->phone}

and {$supplier->company}, {$supplier->address1}, {$supplier->address2} are not apear. Why?

 

Hier is ProductController.php

code...
 $address_id=Address::getAddressIdBySupplierId($this->product->id_supplier);
  $this->context->smarty->assign(array(
				 'supplier' => new Address($address_id),			
   'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
...code

 

And hier product.tpl

code...
<div id="supplier" class="supplier">{$supplier->company} {$supplier->adress1} {$supplier->adress2} {$supplier->postcode} {$supplier->city} {$supplier->phone}</div>

  {/if}
...code

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

maybe you havent got defined those values on supplier edit page?

 

i checked your code, you use:

 

{$supplier->adress1} {$supplier->adress2}

 

it's necessary to use address1 address2

(not adress1 / adress2)

Link to comment
Share on other sites

But if I add old code:

$this->context->smarty->assign(array(
supplier' => new Supplier($this->product->id_supplier,$this->context->language->id),

 

{$supplier->name} appears.

 

By new code

$address_id=Address::getAddressIdBySupplierId($this->product->id_supplier);
  $this->context->smarty->assign(array(
				 'supplier' => new Address($address_id),

 

{$supplier->name} not appears

Link to comment
Share on other sites

because you have to use {$supplier->company}

 

here is a full array wit available variables ($supplier->THIS-IS-VARIABLE}

[id_customer] => 0
   [id_manufacturer] => 0
   [id_supplier] => 1
   [id_warehouse] => 0
   [id_country] => 21
   [id_state] => 32
   [country] => United States
   [alias] => supplier
   [company] => Apple
   [lastname] => supplier
   [firstname] => supplier
   [address1] => 767 Fifth Ave.
   [address2] =>
   [postcode] => 10153
   [city] => New York
   [other] =>
   [phone] => (212) 336-1440
   [phone_mobile] =>
   [vat_number] =>
   [dni] =>
   [date_add] => 2013-05-25 14:31:36
   [date_upd] => 2013-05-25 14:31:36
   [deleted] => 0

Link to comment
Share on other sites

  • 5 months later...

hello

 

countries aren't related to languages in prestashop, but if you use only several countries, you can do it with:

 

upload country flags to /img/l/ directory based on country id field you've got

 

then in product.tpl file use something like:

<img src="{$img_lang_dir}{$ID_OF_COUNTRY_VARIABLE_HERE}.jpg"  />
Link to comment
Share on other sites

 

hello

 

countries aren't related to languages in prestashop, but if you use only several countries, you can do it with:

 

upload country flags to /img/l/ directory based on country id field you've got

 

then in product.tpl file use something like:

<img src="{$img_lang_dir}{$ID_OF_COUNTRY_VARIABLE_HERE}.jpg"  />

 

Hi

Thanks so much for your reply!

I added:

<img src="{$img_lang_dir}{$supplier->id_country}.jpg"/> 

, however, the URL fails to pick up the country variable..

e.g. "http://mystore.com/img/l/.jpg"

 

Do you know why?

 
Thanks!
Link to comment
Share on other sites

I've fixed it woohoo! You said to put {$supplier|print_r} somewhere, so i put it underneath the code. The '1' was near to the 'image not found' where the flag would be. Since the '1' was there, i put it like this '{$supplier->id_country}{$supplier|print_r}', and the flags now show!

Thanks so much for your help, i really appreciate it! 

Link to comment
Share on other sites

Hey,

 

This all worked fine for me :-),

but i was wondering if it is possible to get some information of the $supplier array into a mail template that goes out to the customer.

 

so if anybody has some suggestions i would really appreciate it.

 

if I were you i will create new topic related to emails :) this thread is a bit different (forum rules: 1 topic = 1 question)

im convinced that then someone will help you, for example me :D

Link to comment
Share on other sites

  • 4 weeks later...

I have question which expands problem discussed here. I'm using prestashop 1.5.6.1

 

We can actually assign several suppliers for one product. Lets say its Apple and Shure. And we HAVE TO choose default supplier for that product. Ok lets say its Apple.

 

Now on product page i have in variables only Apple supplier informations. Is there any way to pass object with list of ALL suppliers assigned to this product? (not only one marked as default?) 

 

Something like:

[suppliers_tab]
  [1]
    [supplier id] => 1
    [supplier name] => Apple
    [supplier desc] =>
    ...
  [2]
    [supplier id] => 2
    [supplier name] => Shure
    [supplier desc] =>
    ....

 Let's say i would like to show list of all suppliers for this product on product page.

 

 Any help with this? Thanks in advance.

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

×
×
  • Create New...