Jump to content

Displaying product condition [SOLVED]


bluebolt44

Recommended Posts

Hi all,

 

I am currently working on a catalog (using prestashop obviously!) offering the price but no option to buy and I am struggling with getting the product condition to display correctly. I want the condition to appear with a capitalised first letter (e.g. 'New' not 'new') and I want to add a new option; 'Faulty', to condition.

 

1) I edited \tabs\AdminProducts.php and added the 4th option of "Faulty". This displays correctly in the BackOffice allowing me to select it but does not show when viewing the item in the shop.

<select name="condition" id="condition">
<option value="New" '.($obj->condition == 'new' ? 'selected="selected"' : '').'>'.$this->l('New').'</option>
<option value="Used" '.($obj->condition == 'used' ? 'selected="selected"' : '').'>'.$this->l('Used').'</option>
<option value="Refurbished" '.($obj->condition == 'refurbished' ? 'selected="selected"' : '').'>'.$this->l('Refurbished').'</option>
<option value="Faulty" '.($obj->condition == 'faulty' ? 'selected="selected"' : '').'>'.$this->l('Faulty').'</option>
</select>

 

2) I edited Product.tpl line 238 to say:

{if isset($product->condition)}<spanclass="new">Condition: {l s={$product->condition[spam-filter]</br>(see below){/if}

 

This shows new, used, refurbished where I want (just above the price) but the words are in lower case and items using the option of 'Faulty' are just blank.

 

Any help would be much appreciated, apologies if I have posted in the wrong section!

 

Thanks,

Bluebolt44

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

The problem is that the condition column is defined as an enum in the database:

 

`condition` ENUM('new', 'used', 'refurbished') NOT NULL DEFAULT 'new',

 

So to add a new condition value you would need to alter that column.

 

Cheers

  • Like 1
Link to comment
Share on other sites

Try this to capitalise the option.

{if isset($product->condition)}<spanclass="new" style="text-transform:capitalize;">Condition: {l s={$product->condition[spam-filter]</br>(see below){/if}

As mentioned by codegrunt you will need to alter your sql database to include the faulty option

  • Like 2
Link to comment
Share on other sites

Thanks jhnstcks, that was exactly what I have been looking for and it works perfectly.

 

Which table is it that I need to edit within the database? I couldnt seem to find anything when I searched through.

 

Thanks again!

Link to comment
Share on other sites

Run this

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

Change ps_product to use whatever prefix you use on your table

  • Like 1
Link to comment
Share on other sites

I eventually found it in ps_product after another look and changed it manually (which worked) but I ran your query on my live version of the server and it also worked perfectly.

 

Thanks =)

 

Edit:

I will mark this post as solved and hopefully will provide help for anyone else wanting to display product condition in the front office.

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

  • 1 year later...
  • 10 months later...

I tried to update this option to my prestashop 1.6.0.5 but I guess Im missing something. I know very little about php but followed these instructions given. And I apologize beforehand for not knowing how to quote the coding areas properly.

 

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.

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

Link to comment
Share on other sites

  • 3 weeks later...

I tried to update this option to my prestashop 1.6.0.5 but I guess Im missing something. I know very little about php but followed these instructions given. And I apologize beforehand for not knowing how to quote the coding areas properly.

 

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.

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 have also done all this

 

and then i edited 

 

shop.com/classes/Product.php

 

 

Line 179:

/** @var enum Product condition (stitched, un-stitched, ready-to-wear, made-to-order) */

public $condition;
 
 

Line 291:

'condition' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('stitched', 'un-stitched', 'ready-to-wear', 'made-to-order'), 'default' => 'stitched'),

 

that helped me get rid of this error too

 

so now 

product.tpl (done)

product.php (done)

information.tpl (done)

database table CONDITION also DONE

 

 

still i am seeing NEW, USED, REFURBISHED on my front office :(        WHYYYYYYYYYYYYYY

Link to comment
Share on other sites

shop.com/admin5586/themes/default/template/controllers/products/informations.tpl

 

<div class="form-group">

<label class="control-label col-lg-3" for="condition">

{include file="controllers/products/multishop/checkbox.tpl" field="condition" type="default"}

{l s='Condition'}

</label>

<div class="col-lg-3">

<select name="condition" id="condition">

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

<option value="un-stitched"  {if $product->condition == 'un-stitched'} selected="selected"{/if}>{l s='Un-Stitched'}</option>

<option value="ready-to-wear"  {if $product->condition == 'ready-to-wear'}selected="selected"{/if}>{l s='Ready-to-Wear'}</option>

<option value="made-to-order"  {if $product->condition == 'made-to-order'}selected="selected"{/if}>{l s='Made-to-Order'}</option>

</select>

</div>

</div>

 

 

shop.com/themes/default-bootstrap/product.tpl

 


{capture name=condition}

{if $product->condition == 'stitched'}{l s='Stitched'}

{elseif $product->condition == 'un-stitched'}{l s='Un-Stitched'}

{elseif $product->condition == 'ready-to-wear'}{l s='Ready-to-Wear'}

{elseif $product->condition == 'made-to-order'}{l s='Made-to-Order'}

{/if}

{/capture}

<p id="product_condition"{if !$product->condition} style="display: none;"{/if}>

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

<span class="editable" itemprop="condition">{$smarty.capture.condition}</span>

</p>


 

shop.com/classes/Product.php

 


Line 179: /** @var enum Product condition (stitched, un-stitched, ready-to-wear, made-to-order) */

public $condition;


 

Line 291: 'condition' =>  array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('stitched', 'un-stitched', 'ready-to-wear', 'made-to-order'), 'default' => 'stitched'),

 

Database also done 

ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM('stitched','un-stitched','ready-to-wear','made-to-order') CHARACTER SET utf8 COLLATEutf8_general_ci NOT NULL DEFAULT 'stitched';

 

STILL FRONT OFFICE DISPLAYING NEW, USED condition in left filter coloum :(
Link to comment
Share on other sites

I have noticed 1 thing 

 

i added 1 new product and selected Ready-to-Wear option from condition box and then saved it

 

when the page returned after saving the option was not selected and stitched was on top as before :(

 

so it means the my information tab of new product has some problem is selection of check box option

 

:(

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
  • 3 years later...

Here are the steps to add xtra Condition Field:

  • Run this query in your database ps_product table:

 

ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM( 'new', 'used', 'refurbished', 'faulty' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';
  • Run this query in your database ps_product_shop table:
ALTER TABLE `ps_product_shop` CHANGE `condition` `condition` ENUM( 'new', 'used', 'refurbished', 'faulty' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'new';
  • Changed code in src/PrestaShopBundle/Form/Admin/Product/ProductOptions.php to reflect the new conditions in the product backend:
->add('condition', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
  'choices'  => array(
    $this->translator->trans('New', [], 'Shop.Theme.Catalog') => 'new',
    $this->translator->trans('Pre-Owned', [], 'Shop.Theme.Catalog') => 'used',
    $this->translator->trans('Refurbished', [], 'Shop.Theme.Catalog') => 'refurbished',
    $this->translator->trans('Display Model', [], 'Shop.Theme.Catalog') => 'faulty'
  ),
  'choices_as_values' => true,
  'required' => true,
  'label' => $this->translator->trans('Condition', [], 'Admin.Catalog.Feature')
))
  • Changed the code in classes/Product.php to:
'condition' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('new', 'used', 'refurbished', 'faulty'), 'default' => 'new'),

For Version Lower then 1.5 Changed src/Core/Product/ProductPresenter.php else src/Adapter/Presenter/Product/ProductLazyArray.php:

private function addConditionInformation(
    array $presentedProduct,
    ProductPresentationSettings $settings,
    array $product
) {
    print_r($product);
    switch ($product['condition']) {
        case 'new':
            $presentedProduct['condition'] = array(
                'type' => 'new',
                'label' => $this->translator->trans('New Product', array(), 'Shop.Theme.Catalog'),
                'schema_url' => 'https://schema.org/NewCondition',
            );
            break;
        case 'used':
            $presentedProduct['condition'] = array(
                'type' => 'used',
                'label' => $this->translator->trans('Used', array(), 'Shop.Theme.Catalog'),
                'schema_url' => 'https://schema.org/DisplayModelCondition',
            );
            break;
        case 'refurbished':
            $presentedProduct['condition'] = array(
                'type' => 'refurbished',
                'label' => $this->translator->trans('Refurbished', array(), 'Shop.Theme.Catalog'),
                'schema_url' => 'https://schema.org/RefurbishedCondition',
            );
            break;
		case 'faulty':
            $presentedProduct['condition'] = array(
                'type' => 'faulty',
                'label' => $this->translator->trans('Faulty', array(), 'Shop.Theme.Catalog'),
                'schema_url' => 'https://schema.org/PreOwnedCondition',
            );
            break;
        default:
            $presentedProduct['condition'] = false;
    }

    return $presentedProduct;
}

i hope it helps many :) 

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I am unable to even change product condition in the front office from "New" to any other condition.  Any change made in the back office for product condition is not being displayed at the front office. Is there a way to hide product condition altogether?  I recently installed Prestashop 1.7.6.5 for testing and this is the only "bug" I am unable to get pass.  Any help would be appreciated.

Thank you.

Link to comment
Share on other sites

  • 1 year later...

Hello, I need your help. I've got a site that sales new and refurbished products, on product.tpl i added the code

"{block name='product_condition'}
    <br></br><span style="color: #339966; font-size: 16px">
    {if $product.condition}
      <div class="product-condition">
        <label class="label">{l s='Condition' d='Shop.Theme.Catalog'} </label>
        <link itemprop="itemCondition" href="{$product.condition.schema_url}"/>
        <span>{$product.condition.label}</span>
      </div>
    {/if}</span>
  {/block}", but what I really want is to only show condition of the product if it's refurbished, ando not of all of them, I've got more ten 50.000 products, and I import via CSV, so I can't "untick" each new product do hide the condition. I think I just need an "if" in that code to show only refurbished products.

Link to comment
Share on other sites

1 minuut geleden, NunoACruz zei:

Hello, I need your help. I've got a site that sales new and refurbished products, on product.tpl i added the code

"{block name='product_condition'}
    <br></br><span style="color: #339966; font-size: 16px">
    {if $product.condition}
      <div class="product-condition">
        <label class="label">{l s='Condition' d='Shop.Theme.Catalog'} </label>
        <link itemprop="itemCondition" href="{$product.condition.schema_url}"/>
        <span>{$product.condition.label}</span>
      </div>
    {/if}</span>
  {/block}", but what I really want is to only show condition of the product if it's refurbished, ando not of all of them, I've got more ten 50.000 products, and I import via CSV, so I can't "untick" each new product do hide the condition. I think I just need an "if" in that code to show only refurbished products.

PLease open a new post. This is a post from 2014. Also give as much information as you have: Prestashop version etc.

Link to comment
Share on other sites

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