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)
-   -   x5 New 'Short Description' Field in Categories - Solution and Question... (https://forum.x-cart.com/showthread.php?t=71796)

xgarb 04-08-2015 03:58 AM

x5 New 'Short Description' Field in Categories - Solution and Question...
 
Using the example here as a guide: http://kb.x-cart.com/display/XDD/Adding+new+property+to+a+product

I've added a new field to the category admin screen to add short descriptions.

My code looks like this:

In XLite/Module/Client/ClientCatsShortDescriptions/Model/CategoryTranslation.php

Code:

namespace XLite\Module\Client\ClientCatsShortDescriptions\Model;
 
class CategoryTranslation extends \XLite\Model\CategoryTranslation implements \XLite\Base\IDecorator
{
    /**
    * @Column (type="string", length=255)
    */
    protected $shortDescr;
}


In XLite/Module/Client/ClientCatsShortDescriptions/View/Model/Category.php

Code:

namespace XLite\Module\Client\ClientCatsShortDescriptions\View\Model;
 
class Category extends \XLite\View\Model\Category implements \XLite\Base\IDecorator
{
    public function __construct(array $params = array(), array $sections = array())
    {
        parent::__construct($params, $sections);
 
        $this->schemaDefault += array (
            'shortDescr' => array(
                self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Advanced',
                self::SCHEMA_LABEL    => 'Short Description',
                self::SCHEMA_REQUIRED => false,
                ),
            );
    }
}


in my template listing the categories (cut down for clarity)...
Code:

{foreach:getSubcategories(),subcategory}
      {subcategory.name}<br>
      {subcategory.shortdescr:h}
{end:}


So this works very nicely except in admin the form field for entering the short descriptions is at the bottom of the page.

How can I move it to be above the normal description box?

I tried
Code:

ALTER TABLE `xc_category_translations` MODIFY `shortDescr` VARCHAR(255) AFTER `name`
in the database but it doesn't have any effect.

I guess it's something to do with the module being called last on the page?

tony_sologubov 04-08-2015 01:27 PM

Re: x5 New 'Short Description' Field in Categories - Solution and Question...
 
In your __construct() class you must reorganize the schemaDefault array and put your shortDescr field right above usual Description field instead of adding it to the bottom of the array.

Please, let me know if it makes sense to you.

Tony

xgarb 04-09-2015 12:21 AM

Re: x5 New 'Short Description' Field in Categories - Solution and Question...
 
Ah.. I did this...

In XLite/Module/Client/ClientCatsShortDescriptions/View/Model/Category.php now I have

Code:

namespace XLite\Module\Client\ClientCatsShortDescriptions\View\Model;
 
class Category extends \XLite\View\Model\Category implements \XLite\Base\IDecorator
{
    public function __construct(array $params = array(), array $sections = array())
    {
        parent::__construct($params, $sections);
 
        $this->schemaDefault = array (

        'name' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Category name',
            self::SCHEMA_REQUIRED => true,
        ),
        'show_title' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\CategoryShowTitle',
            self::SCHEMA_LABEL    => 'Show Category title',
            self::SCHEMA_REQUIRED => false,
        ),
        'image' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\FileUploader\Image',
            self::SCHEMA_LABEL    => 'Category icon',
            self::SCHEMA_REQUIRED => false,
        ),
      'shortDescr' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Advanced',
            self::SCHEMA_LABEL    => 'Short Description',
            self::SCHEMA_REQUIRED => false,
        ),
        'description' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Advanced',
            self::SCHEMA_LABEL    => 'Description',
            self::SCHEMA_REQUIRED => false,
            \XLite\View\FormField\Textarea\Advanced::PARAM_STYLE => 'category-description',
        ),
        'cleanURL' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text\CleanURL',
            self::SCHEMA_LABEL    => 'Clean URL',
            self::SCHEMA_REQUIRED => false,
            \XLite\View\FormField\Input\Text\CleanURL::PARAM_OBJECT_CLASS_NAME => '\XLite\Model\Category'
        ),
        'meta_title' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Custom HTML title',
            self::SCHEMA_HELP    => 'Leave the field empty to autogenerate a value for the HTML title tag',
            self::SCHEMA_REQUIRED => false,
        ),
        'meta_tags' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Meta tags',
            self::SCHEMA_REQUIRED => false,
        ),
        'meta_desc' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Simple',
            self::SCHEMA_LABEL    => 'Meta desc',
            self::SCHEMA_REQUIRED => false,
        ),
        'memberships' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\Memberships',
            self::SCHEMA_LABEL    => 'Memberships',
            self::SCHEMA_REQUIRED => false,
        ),
        'enabled' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Checkbox\Enabled',
            self::SCHEMA_LABEL    => 'Enabled',
            self::SCHEMA_REQUIRED => false,
        ),

      );
    }
}


Seems to work.

Cool!

xgarb 08-07-2015 01:40 AM

Re: x5 New 'Short Description' Field in Categories - Solution and Question...
 
UPDATE

For 5.2.6 function method needs to look like this...

Code:

    public function __construct(array $params = array(), array $sections = array())
    {
        parent::__construct($params, $sections);
 
        $this->schemaDefault = array(
               
        'name' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Category name',
            self::SCHEMA_REQUIRED => true,
        ),
        'parent' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\Category',
            self::SCHEMA_LABEL    => 'Parent category',
            self::SCHEMA_REQUIRED => true,
        ),
        'show_title' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\CategoryShowTitle',
            self::SCHEMA_LABEL    => 'Show Category title',
            self::SCHEMA_REQUIRED => false,
        ),
        'image' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\FileUploader\Image',
            self::SCHEMA_LABEL    => 'Category icon',
            self::SCHEMA_REQUIRED => false,
        ),
      'shortDescr' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Advanced',
            self::SCHEMA_LABEL    => 'Short Description',
            self::SCHEMA_REQUIRED => false,
        ),               
        'description' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Advanced',
            self::SCHEMA_LABEL    => 'Description',
            self::SCHEMA_REQUIRED => false,
            \XLite\View\FormField\Textarea\Advanced::PARAM_STYLE => 'category-description',
        ),
        'cleanURL' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text\CleanURL',
            self::SCHEMA_LABEL    => 'Clean URL',
            self::SCHEMA_REQUIRED => false,
            \XLite\View\FormField\AFormField::PARAM_LABEL_HELP => 'Human readable and SEO friendly web address for the page.',
            \XLite\View\FormField\Input\Text\CleanURL::PARAM_OBJECT_CLASS_NAME => 'XLite\Model\Category'
        ),
        'meta_title' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Category page title',
            self::SCHEMA_REQUIRED => false,
            self::SCHEMA_COMMENT  => 'Leave blank to use category name as Page Title.',
        ),
        'meta_tags' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            self::SCHEMA_LABEL    => 'Meta keywords',
            self::SCHEMA_REQUIRED => false,
        ),
        'meta_desc_type' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\MetaDescriptionType',
            self::SCHEMA_LABEL    => 'Meta description',
            self::SCHEMA_REQUIRED => false,
        ),
        'meta_desc' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Textarea\Simple',
            self::SCHEMA_LABEL    => '',
            \XLite\View\FormField\AFormField::PARAM_USE_COLON => false,
            self::SCHEMA_REQUIRED => false,
            self::SCHEMA_DEPENDENCY => array(
                self::DEPENDENCY_SHOW => array (
                    'meta_desc_type' => array('C'),
                )
            ),
        ),
        'memberships' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\Memberships',
            self::SCHEMA_LABEL    => 'Memberships',
            self::SCHEMA_REQUIRED => false,
        ),
        'enabled' => array(
            self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Checkbox\Enabled',
            self::SCHEMA_LABEL    => 'Enabled',
            self::SCHEMA_REQUIRED => false,
        ),
    );


    }



All times are GMT -8. The time now is 05:40 AM.

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