Jump to content

Changing product "condition" values


elisam98

Recommended Posts

I have a shop where the customer needs to change the condition options for products. Instead of the standard options "new", "used", and "refurbished". They need "new", "display", "preowned", and "refurbished".
 
Following the answer for PS 1.6 from https://www.prestashop.com/forums/topic/513876-change-product-condition-labels/, I have been able to change the backend to store these values in the ps_product table (with some adaptations for PS 1.7 - details below).
However, when I save the product with any option besides for the original "new" or "refurbished" conditions, the frontend thinks that there is no condition value for the product and will not display the condition on the product page in the frontend.
 
Here are the steps I took to get me to this point:

  • Ran this query on my ps_product table:
    ALTER TABLE `ps_product` CHANGE `condition` `condition` ENUM( 'new', 'display', 'refurbished', 'preowned' ) 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') => 'preowned',
        $this->translator->trans('Display Model', [], 'Shop.Theme.Catalog') => 'display',
        $this->translator->trans('Refurbished', [], 'Shop.Theme.Catalog') => 'refurbished'
      ),
      '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', 'preowned', 'display', 'refurbished'), 'default' => 'new'),
    
  • Changed src/Core/Product/ProductPresenter.php to:
    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 'display':
                $presentedProduct['condition'] = array(
                    'type' => 'display',
                    'label' => $this->translator->trans('Display Model', array(), 'Shop.Theme.Catalog'),
                    'schema_url' => 'https://schema.org/DisplayModelCondition',
                );
                break;
            case 'preowned':
                $presentedProduct['condition'] = array(
                    'type' => 'preowned',
                    'label' => $this->translator->trans('Pre-Owned', array(), 'Shop.Theme.Catalog'),
                    'schema_url' => 'https://schema.org/PreOwnedCondition',
                );
                break;
            case 'refurbished':
                $presentedProduct['condition'] = array(
                    'type' => 'refurbished',
                    'label' => $this->translator->trans('Refurbished', array(), 'Shop.Theme.Catalog'),
                    'schema_url' => 'https://schema.org/RefurbishedCondition',
                );
                break;
            default:
                $presentedProduct['condition'] = false;
        }
    
        return $presentedProduct;
    }
    

So now, even though the backend works and the new values are being saved correctly in my ps_product table, the frontend will not display any condition value if I choose "preowned" or "display" in the backend.
Any ideas?

Link to comment
Share on other sites

  • 4 months later...

Got this one to work.

You also need to edit the ps_product_shop table, and if you want the faceted search to work change the code in facetedsearch.php.

 

as for your code, the schema.org links may be best to keep them to an existing product condition page instead of a non existing page

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

  • 1 year later...

Hello and thank you for this thread as I just applied this modification for my website with success !

 

Unfortunately I cannot see the new condition fields as localizable in the classic theme under the Shop > Theme > Catalog translation section. This way the new conditions are in english language despite the website language used :( Am I missing something or do you have the same behaviour with this modification ?

Link to comment
Share on other sites

  • 9 months later...

Hello, thank you for your answer !

Just for your informations in Prestashop 1.7.5.1 (and apparently since 1.7.4) the switch that we have to modify with new condition in src/Core/Product/ProductPresenter.php is now located here /src/Adapter/Presenter/Product/ProductLazyArray.php

Edited by sachacohenfr
information missing (see edit history)
Link to comment
Share on other sites

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