X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Adding multiple new properties to a product trouble (https://forum.x-cart.com/showthread.php?t=78514)

galoadm 03-02-2023 10:52 AM

Adding multiple new properties to a product trouble
 
I am following the "Add a New Property to a Product" instructions and am having a little trouble adding multiple properties in X-Cart 5.4. Adding a single property works fine, but adding multiple properties is making the product description, name, images, and category disappear from the back and front end while displaying all the new properties.

My code for decorating viewer class:

Code:

<?php
// vim: set ts=4 sw=4 sts=4 et:

namespace XLite\Module\*******\*******\View\FormModel\Product;

/**
 * Product form model
 */
abstract class Info extends \XLite\View\FormModel\Product\Info implements \XLite\Base\IDecorator
{
    protected function defineFields()
    {
        $schema = parent::defineFields();

        $schema = ['default' => [
                'myBrand' => [
            'label'    => static::t('Brand'),
            'position'  => 900,
        ],
               
                'myCountryOrigin' => [
            'label'    => static::t('Country of Origin'),
            'position'  => 910,
        ],
               
                'myCountryAssembly' => [
            'label'    => static::t('Assembly Location'),
            'position'  => 920,
        ],
               
                'myItemCondition' => [
            'label'    => static::t('Item Condition'),
            'position'  => 930,
        ],
               
                'myMaterial' => [
            'label'    => static::t('Made of'),
            'position'  => 940,
        ],
        ],
        ];
        return $schema;
    }

}



Instructions code for decorating viewer class:

Code:

<?php
// vim: set ts=4 sw=4 sts=4 et:
 
namespace XLite\Module\XCExample\ProductPropertyDemo\View\FormModel\Product;
 
/**
 * Product form model
 */
abstract class Info extends \XLite\View\FormModel\Product\Info implements \XLite\Base\IDecorator
{
    protected function defineFields()
    {
        $schema = parent::defineFields();
 
        $schema['default']['myMessage'] = [
            'label'    => static::t('My message'),
            'position'  => 900,
        ];
 
        return $schema;
    }
 
}



Any help will be most appreciated.

cflsystems 03-02-2023 12:06 PM

Re: Adding multiple new properties to a product trouble
 
Code:

$schema = parent::defineFields();


$schema = ['default' => [......



You are overriding $schema with your custom line. You should be adding to it your new fields whether you want them to show

galoadm 03-02-2023 01:14 PM

Re: Adding multiple new properties to a product trouble
 
Thank you. Could you elaborate on how to do that?

galoadm 03-02-2023 01:24 PM

Re: Adding multiple new properties to a product trouble
 
Would I just add each separately like this:

Code:

$schema = parent::defineFields();

        $schema['default']['myBrand'] = [
            'label'    => static::t('Brand'),
            'position'  => 900,
        ];
        $schema['default']['myCountryOrigin'] = [
            'label'    => static::t('Country of Origin'),
            'position'  => 910,
        ];


etc.

cflsystems 03-03-2023 06:33 AM

Re: Adding multiple new properties to a product trouble
 
You can do that, you can use array_merge as well

galoadm 03-03-2023 07:39 AM

Re: Adding multiple new properties to a product trouble
 
Thank you. I appreciate the assistance.


All times are GMT -8. The time now is 06:55 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.