Jump to content

Adding options to product condition list


Recommended Posts

I tried to update this option to my prestashop 1.6.0.5 but I guess I'm missing something. I know just enough about php to edit by instruction. I found a thread for a previous 1.4 PS version and I am trying to adapt it for version 1.6.

 

First I went to admin/themes/default/template/controllers/products and opened the information.tpl and added:

<option value="custom build" {if $product->condition == 'custom build'}selected="selected"{/if} >{l s='Custom Build'}</option>

after this line:

<option value="refurbished" {if $product->condition == 'refurbished'}selected="selected"{/if}>{l s='Refurbished'}</option>

Then

I went to themes/products.tpl and added:

{elseif $product->condition == 'custom build'}{l s='Custom Build'}

after this line:

{elseif $product->condition == 'refurbished'}{l s='Refurbished'}

Then

I ran this:

ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM( 'new', 'used', 'refurbished', 'custom build' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new'

in ps_products in my db using PHPadmin

I check the db under ps_products/conditions and the query was accepted.

I also went to classes/Product.php and added "custom build" to the options:

/** @var enum Product condition (new, used, refurbished, custom build) */
    public $condition;

And I had to add the same query

ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM( 'new', 'used', 'refurbished', 'custom build' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new'

to ps_product_shop in the db using PHPMyadmin

 

and this is the error that I get in my admin section when I select the custom build from the information page under my product:

Property Product->condition has bad value (allowed values are: new, used, refurbished)

 

Any help on what step I'm missing, skipped or messed up on would be appreciated. I post this originally here... http://www.prestashop.com/forums/topic/331966-adding-options-to-product-condition-list/ but got no response for a week.

 

  • Like 1
Link to comment
Share on other sites

Why can't I get anyone to respond to my posts. I posted this problem in the development section for a week and got no response after several requests. I even asked if it was ok before I posted this in another section since I didn't get a response and still no answer. I've now posted this in the 1.6 section for 2 days now and still no response. If I've broken some forum rule or not adhered to some netizen ettiquette please let me know so I can rectify it. 

 

All I'm looking for is a little direction on how to finish this modification. If it's not possible in 1.6 then please respond and I will move on. But I'm on day 12 now with looking to this forum to give me advice and haven't even gotten so much as an acknowledgement of my existence.

 

Can anyone here @ prestashop provide me with any help. Anything or anyone would be appreciated.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Well Cybermatrix, you helped me figure out my problem via posting your issues,

I hope I can help you now, (BTW this is my first post)

I was headed down the same path as you, and wanted to create a whole new condition, not just change the translation of one. So here are the steps I did, which were very similar except a couple different ones, and it appears to be working for me now :)

I edited 4 files, and added two DB entries, to get it to work, now I'm not completely sure if all 4 files needed to be edited but it's working.

I was adding the condition "autographed" with the text being "New - Autographed" 

 

1st) themes/default-bootstrap/product.tpl

{capture name=condition}
	{if $product->condition == 'new'}{l s='New'}
	  {elseif $product->condition == 'used'}{l s='Used'}
	  {elseif $product->condition == 'refurbished'}{l s='Refurbished'}
	  {elseif $product->condition == 'autographed'}{l s='New - Autographed'}
	{/if}
{/capture}

2nd) admin123/themes/default/template/controllers/products/informations.tpl

<select name="condition" id="condition">
<option value="new" {if $product->condition == 'new'}selected="selected"{/if} >{l s='New'}</option>
<option value="used" {if $product->condition == 'used'}selected="selected"{/if} >{l s='Used'}</option>
<option value="refurbished" {if $product->condition == 'refurbished'}selected="selected"{/if} >{l s='Refurbished'}</option>
<option value="autographed" {if $product->condition == 'autographed'}selected="selected"{/if} >{l s='New - Autographed'}</option>
</select>

3rd) classes/Product.php

/** @var enum Product condition (new, used, refurbished, autographed) */
public $condition;

I don't think it's necessary to edit the above line since it appears to be commented out, but i went ahead and did it anyways...

'condition' =>	array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('new', 'used', 'refurbished', 'autographed'), 'default' => 'new'),

4th) modules/blocklayered/blocklayered.php     (this one had a lot of locations for conditions and I added to each)

case 'condition':
$condition_list = array(
	'new' => $this->translateWord('New', (int)$filter['id_lang']),
	'used' => $this->translateWord('Used', (int)$filter['id_lang']),
	'refurbished' => $this->translateWord('Refurbished', (int)$filter['id_lang']),
	'autographed' => $this->translateWord('New - Autographed', (int)$filter['id_lang'])
);

(Don't forget the comma at the end of the previous line)

preg_match('/^(.*)_([0-9]+|new|used|refurbished|autographed|slider)$/', substr($key, 8, strlen($key) - 8), $res);
if ($res[1] == 'condition' && in_array($value, array('new', 'used', 'refurbished', 'autographed')))
$condition_array = array(
	'new' => array('name' => $this->l('New'),'nbr' => 0), 
	'used' => array('name' => $this->l('Used'), 'nbr' => 0),
	'refurbished' => array('name' => $this->l('Refurbished'), 'nbr' => 0),
	'autographed' => array('name' => $this->l('New - Autographed'),
	'nbr' => 0)

-Take note of the ,'nbr' => 0), at the end of the previous line, I missed this the first time and broke my whole site, admin side and everything :)

 

Now for the DB additions:

ALTER TABLE `psXXYY_product` CHANGE `condition` `condition` ENUM('new','used','refurbished','autographed') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';
ALTER TABLE `psXXYY_product_shop` CHANGE `condition` `condition` ENUM('new','used','refurbished','autographed') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';

(Don't forget to change XXYY to your table prefix for your database)

The final thing that helped me, because of what you were posting was the addition to the ps_product_shop table, which I had completely missed, but when I looked at your code, you only had ps_product in the alter table command...

I hope this helps, this is exactly what I did, and it appears to be working for me, through all the testing I've done.

-Jake

Edited by jbob23 (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Well Cybermatrix, you helped me figure out my problem via posting your issues,

I hope I can help you now, (BTW this is my first post)

I was headed down the same path as you, and wanted to create a whole new condition, not just change the translation of one. So here are the steps I did, which were very similar except a couple different ones, and it appears to be working for me now :)

I edited 4 files, and added two DB entries, to get it to work, now I'm not completely sure if all 4 files needed to be edited but it's working.

I was adding the condition "autographed" with the text being "New - Autographed" 

 

1st) themes/default-bootstrap/product.tpl

{capture name=condition}
	{if $product->condition == 'new'}{l s='New'}
	  {elseif $product->condition == 'used'}{l s='Used'}
	  {elseif $product->condition == 'refurbished'}{l s='Refurbished'}
	  {elseif $product->condition == 'autographed'}{l s='New - Autographed'}
	{/if}
{/capture}

2nd) admin123/themes/default/template/controllers/products/informations.tpl

<select name="condition" id="condition">
<option value="new" {if $product->condition == 'new'}selected="selected"{/if} >{l s='New'}</option>
<option value="used" {if $product->condition == 'used'}selected="selected"{/if} >{l s='Used'}</option>
<option value="refurbished" {if $product->condition == 'refurbished'}selected="selected"{/if} >{l s='Refurbished'}</option>
<option value="autographed" {if $product->condition == 'autographed'}selected="selected"{/if} >{l s='New - Autographed'}</option>
</select>

3rd) classes/Product.php

/** @var enum Product condition (new, used, refurbished, autographed) */
public $condition;

I don't think it's necessary to edit the above line since it appears to be commented out, but i went ahead and did it anyways...

'condition' =>	array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('new', 'used', 'refurbished', 'autographed'), 'default' => 'new'),

4th) modules/blocklayered/blocklayered.php     (this one had a lot of locations for conditions and I added to each)

case 'condition':
$condition_list = array(
	'new' => $this->translateWord('New', (int)$filter['id_lang']),
	'used' => $this->translateWord('Used', (int)$filter['id_lang']),
	'refurbished' => $this->translateWord('Refurbished', (int)$filter['id_lang']),
	'autographed' => $this->translateWord('New - Autographed', (int)$filter['id_lang'])
);

(Don't forget the comma at the end of the previous line)

preg_match('/^(.*)_([0-9]+|new|used|refurbished|autographed|slider)$/', substr($key, 8, strlen($key) - 8), $res);
if ($res[1] == 'condition' && in_array($value, array('new', 'used', 'refurbished', 'autographed')))
$condition_array = array(
	'new' => array('name' => $this->l('New'),'nbr' => 0), 
	'used' => array('name' => $this->l('Used'), 'nbr' => 0),
	'refurbished' => array('name' => $this->l('Refurbished'), 'nbr' => 0),
	'autographed' => array('name' => $this->l('New - Autographed'),
	'nbr' => 0)

-Take note of the ,'nbr' => 0), at the end of the previous line, I missed this the first time and broke my whole site, admin side and everything :)

 

Now for the DB additions:

ALTER TABLE `psXXYY_product` CHANGE `condition` `condition` ENUM('new','used','refurbished','autographed') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';
ALTER TABLE `psXXYY_product_shop` CHANGE `condition` `condition` ENUM('new','used','refurbished','autographed') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';

(Don't forget to change XXYY to your table prefix for your database)

The final thing that helped me, because of what you were posting was the addition to the ps_product_shop table, which I had completely missed, but when I looked at your code, you only had ps_product in the alter table command...

I hope this helps, this is exactly what I did, and it appears to be working for me, through all the testing I've done.

-Jake

This worked perfectly for me. I was able to follow your instructions to the letter and now I have a 'Vintage' option to choose from my drop down Condition field. Thanks a million for posting this here, it was very appreciated!

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Awesome! Glad it helped, happy selling!  :D

Hello,

 

I tried everything but after doing all the modifications my shop & even the admin side is not working anymore.

 

The change below I can't find it in the products.tpl

 

1st) themes/default-bootstrap/product.tpl

  1. {capture name=condition}
  2.     {if $product->condition == 'new'}{l s='New'}
  3.      {elseif $product->condition == 'used'}{l s='Used'}
  4.      {elseif $product->condition == 'refurbished'}{l s='Refurbished'}
  5.      {elseif $product->condition == 'autographed'}{l s='New - Autographed'}
  6.     {/if}
  7. {/capture}

I found this one in the product.tpl file

 

<p id="product_condition">

    <label>{l s='Condition'} </label>

    {if $product->condition == 'new'}

     <link itemprop="itemCondition" href="http://schema.org/NewCondition"/>

     <span class="editable">{l s='New'}</span>

    {elseif $product->condition == 'used'}

     <link itemprop="itemCondition" href="http://schema.org/UsedCondition"/>

     <span class="editable">{l s='Used'}</span>

    {elseif $product->condition == 'refurbished'}

     <link itemprop="itemCondition" href="http://schema.org/RefurbishedCondition"/>

     <span class="editable">{l s='Refurbished'}</span>

    {/if}

 

I added a new line :

 

<p id="product_condition">

    <label>{l s='Condition'} </label>

    {if $product->condition == 'new'}

     <link itemprop="itemCondition" href="http://schema.org/NewCondition"/>

     <span class="editable">{l s='New'}</span>

    {elseif $product->condition == 'used'}

     <link itemprop="itemCondition" href="http://schema.org/UsedCondition"/>

     <span class="editable">{l s='Used'}</span>

    {elseif $product->condition == 'refurbished'}

     <link itemprop="itemCondition" href="http://schema.org/RefurbishedCondition"/>

     <span class="editable">{l s='Refurbished'}</span>

     {elseif $product->condition == 'handmade'}

     <link itemprop="itemCondition" href="http://schema.org/HandmadeCondition"/>

     <span class="editable">{l s='Handmade}</span>

    {/if}

 

Still no result.

 

Please can somebody help ?

 

Thank

Link to comment
Share on other sites

  • 3 months later...

I started to edit by the plan presented by jbob23, go through some steps

 

1. Through the Hosting control panel  I can edit  tpl files ,

but cannot edit php   - product.php and  blocklayered.php . 

 

UPD: Hosting people adviced me that there is a restriction for direct editing (via control panel) of large files and recommend me to use FTP  - will do a bit later

 

2. Regarding note of "What to add" by   [email protected]

<p id="product_condition">
    <label>{l s='Condition'} </label>
    {if $product->condition == 'new'}
     <link itemprop="itemCondition" href="http://schema.org/NewCondition"/>
     <span class="editable">{l s='New'}</span>
    {elseif $product->condition == 'used'}
     <link itemprop="itemCondition" href="http://schema.org/UsedCondition"/>
     <span class="editable">{l s='Used'}</span>
    {elseif $product->condition == 'refurbished'}
     <link itemprop="itemCondition" href="http://schema.org/Re...shedCondition"/>
     <span class="editable">{l s='Refurbished'}</span>
     {elseif $product->condition == 'handmade'}
     <link itemprop="itemCondition" href="http://schema.org/HandmadeCondition"/>
     <span class="editable">{l s='Handmade'}</span>
    {/if}

I found the following http://schema.org/OfferItemCondition

 

And Damaged condition added in the scheme:  http://schema.org/DamagedCondition

 

So I risked to edit as follows

<p id="product_condition">
    <label>{l s='Condition'} </label>
    {if $product->condition == 'new'}
     <link itemprop="itemCondition" href="http://schema.org/NewCondition"/>
     <span class="editable">{l s='New'}</span>
    {elseif $product->condition == 'used'}
     <link itemprop="itemCondition" href="http://schema.org/UsedCondition"/>
     <span class="editable">{l s='Used'}</span>
    {elseif $product->condition == 'refurbished'}
     <link itemprop="itemCondition" href="http://schema.org/Re...shedCondition"/>
     <span class="editable">{l s='Refurbished'}</span>
     {elseif $product->condition == 'damaged'}
     <link itemprop="itemCondition" href="http://schema.org/DamagedCondition"/>
     <span class="editable">{l s='Damaged'}</span>
    {/if}

Update

 

3. I did all files modifications offered by jbob23.

product.tpl

information.tpl

product.php 

blocklayered.php

 

4. I run two different SQL queries

ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM('new','used','refurbished','damaged') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';
ALTER TABLE `ps_product_shop` CHANGE `condition` `condition` ENUM('new','used','refurbished','damaged') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';

(frankly I am not good in understanding the details and responses - PHPMyadmin return null record in both cases - guess it is normal as not yet products with the new condition (damaged) inside

 

Please see screenshot  http://joxi.ru/Grqyqv0SbdkDrz

 

5. The result 

  • BO - Product information - damaged option appears in the drop down list of condition options
  • When did I try to assign the product with the new option and see - blank of the BO  page appeared with Internal server error 500
  • Same result - for FO for sure

Any idea - which steps were missed or wrong?

 

Thank You in advance

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

×
×
  • Create New...