Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Adding a new property to a category

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 04-16-2018, 03:45 PM
 
MatiasRS MatiasRS is offline
 

Newbie
  
Join Date: Apr 2018
Posts: 7
 

Post Adding a new property to a category

Greetings.

I recently read this tutorial which shows how to add a new custom property to a product:

https://devs.x-cart.com/basics/adding_new_property_to_a_product/

I am now attempting to do the same thing but for a category. However, I have yet to find the correct viewer class to decorate so that the new property is displayed in the admin page.
Basically, I would like to know where I can find the Info.php file for Category.

Thank you.
__________________
X-Cart 5.3.4
Add-ons: 2Checkout.com, Authorize.Net SIM, Barclaycard ePDQ e-Commerce, Bestsellers, Bulk Editing, CloudSearch & CloudFilters,
Concierge, Contact us, Coupons, Fast Lane Checkout,
Featured Products,
FedEx,
Flyout Categories Menu, Free Shipping and Shipping freights, Froala WYSIWYG editor integration, Go Social, Google Analytics, iDEAL Payments,
MailChimp Integration with E-commerce support, Multicurrency, News, Newsletter subscriptions, Not Finished Orders, Onboarding Wizard,
PayPal, Product Advisor, Product reviews, QuantumGateway, Related Products, Sage Pay (Form), Sale, Sales Tax, Simple CMS, Skrill, Social Login, Stripe, Theme tweaker, Translation: British English, Update Inventory,
UPS, User permissions,
Value Added Tax / Goods and Services Tax,
Volume Discounts,
X-Payments connector,
XML sitemap
Reply With Quote
  #2  
Old 04-16-2018, 06:35 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Adding a new property to a category

Only Product uses DTO. Category - depends on what you need
classes/XLite/View/Model/Category.php
classes/XLite/View/Form/Category/Modify/Single.php
classes/XLite/Controller/Admin/Category.php
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 04-17-2018, 07:51 AM
 
MatiasRS MatiasRS is offline
 

Newbie
  
Join Date: Apr 2018
Posts: 7
 

Default Re: Adding a new property to a category

I see. What I would like to do is adding a new field in the Category info form in the admin page so that the user can change a new string attribute of said category. Which file should I therefore decorate to achieve that?
And if Category doesn't use DTO, how can I make Xcart save the changes to the database?
__________________
X-Cart 5.3.4
Add-ons: 2Checkout.com, Authorize.Net SIM, Barclaycard ePDQ e-Commerce, Bestsellers, Bulk Editing, CloudSearch & CloudFilters,
Concierge, Contact us, Coupons, Fast Lane Checkout,
Featured Products,
FedEx,
Flyout Categories Menu, Free Shipping and Shipping freights, Froala WYSIWYG editor integration, Go Social, Google Analytics, iDEAL Payments,
MailChimp Integration with E-commerce support, Multicurrency, News, Newsletter subscriptions, Not Finished Orders, Onboarding Wizard,
PayPal, Product Advisor, Product reviews, QuantumGateway, Related Products, Sage Pay (Form), Sale, Sales Tax, Simple CMS, Skrill, Social Login, Stripe, Theme tweaker, Translation: British English, Update Inventory,
UPS, User permissions,
Value Added Tax / Goods and Services Tax,
Volume Discounts,
X-Payments connector,
XML sitemap
Reply With Quote
  #4  
Old 04-17-2018, 09:27 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Adding a new property to a category

You may need to decorate all of the files I listed. To make changes to categories table you need to decorate classes/XLite/Model/Category.php.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 04-18-2018, 03:18 PM
 
MatiasRS MatiasRS is offline
 

Newbie
  
Join Date: Apr 2018
Posts: 7
 

Default Re: Adding a new property to a category

Alas, I have tried decorating all three classes using the tutorial as rough guide, but without avail.

To clarify, this is what I'm trying to do:

I want to create a new property called Genre for Category. First, I decorated classes/XLite/View/Model/Category.php like so:

<?php

namespace XLite\Module\XCExample\DesignChangesDemo\Model;

abstract class Category extends \XLite\Model\Category implements \XLite\Base\IDecorator
{
/**
* @Column (type="string")
*/
protected $genre;

public function getGenre()
{
return $this->genre;
}

public function setGenre($value)
{
$this->genre = $value;
return $this;
}
}

I would now like to have the field with the new genre property to show up in the admin Category info page. Following the tutorial, this is the code I came up with:

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

namespace XLite\Module\XCExample\DesignChangesDemo\Controlle r\Admin;

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

$schema['default']['genre'] = [
'label' => static::t('Genre'),
'position' => 900,
];

return $schema;
}

}

I also adapted and pasted the previous code for classes/XLite/View/Form/Category/Modify/Single.php

Nothing has worked so far. Any ideas?
__________________
X-Cart 5.3.4
Add-ons: 2Checkout.com, Authorize.Net SIM, Barclaycard ePDQ e-Commerce, Bestsellers, Bulk Editing, CloudSearch &amp; CloudFilters,
Concierge, Contact us, Coupons, Fast Lane Checkout,
Featured Products,
FedEx,
Flyout Categories Menu, Free Shipping and Shipping freights, Froala WYSIWYG editor integration, Go Social, Google Analytics, iDEAL Payments,
MailChimp Integration with E-commerce support, Multicurrency, News, Newsletter subscriptions, Not Finished Orders, Onboarding Wizard,
PayPal, Product Advisor, Product reviews, QuantumGateway, Related Products, Sage Pay (Form), Sale, Sales Tax, Simple CMS, Skrill, Social Login, Stripe, Theme tweaker, Translation: British English, Update Inventory,
UPS, User permissions,
Value Added Tax / Goods and Services Tax,
Volume Discounts,
X-Payments connector,
XML sitemap
Reply With Quote
  #6  
Old 04-23-2018, 01:21 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Adding a new property to a category

Neither \XLite\Controller\Admin\Category, nor \XLite\Controller\Admin\Category classes control what fields are displayed on the "Edit category" page.

It is \XLite\View\Model\Category (and it's parent \XLite\View\Model\AModel).

Please check how the existing classes configure fields for the page, and decorate \XLite\View\Model\Category from your module.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #7  
Old 05-07-2018, 06:09 AM
 
mcupka mcupka is offline
 

eXpert
  
Join Date: Jan 2013
Posts: 204
 

Default Re: Adding a new property to a category

Hello,

Was this ever figured out? I'm trying to add a custom field 'ie: Test' to my Category page, so I can then use that field value and output it wherever I want.
Reply With Quote
  #8  
Old 05-07-2018, 06:30 AM
 
mcupka mcupka is offline
 

eXpert
  
Join Date: Jan 2013
Posts: 204
 

Default Re: Adding font-awesome icons to category sidebar

Hi Alex,

This is something I would only want on the backend. I added a new field to XLite/View/Model/Category.php
HTML Code:
'nav_icon' => array( self::SCHEMA_CLASS => 'XLite\View\FormField\Textarea\Simple', self::SCHEMA_LABEL => '', \XLite\View\FormField\AFormField::PARAM_USE_COLON => false, self::SCHEMA_REQUIRED => true, self::SCHEMA_DEPENDENCY => array( self::DEPENDENCY_SHOW => array ( 'nav_icon' => array('C'), ) ),

Still a bit confused on all the files/etc I'd need to edit.

To summarize what I really want to do:
- Admin navigates to 'Catalog -> Our Products'
- Admin clicks on a category to edit.
- Where the field 'Category name' is, I'd like to add my own custom field -- for example 'Navigation Icon'.

Then the field becomes usable to call, ie: how {{ this._category.name }} is used in the sidebar menu. So then I'd have a {{ this._category.nav_icon }} or something similar.
Reply With Quote
  #9  
Old 05-10-2018, 03:02 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Adding a new property to a category

Hi @mcupka,

There is an article that describes how to add new property to product in X-Cart 5.1 - 5.2:
https://devs.x-cart.com/basics/model_editing_page.html

The same principle works for editing category page in X-Cart 5.3.

Basically, you will only need to decorate \XLite\View\Model\Category class and define its constructor method as follows:

Code:
public function __construct(array $params = array(), array $sections = array()) { $this->schemaDefault['your_field'] = [] // your definition of the field parent::__construct($params, $sections); }

Please, let us know, if it helps.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #10  
Old 05-10-2018, 08:38 AM
 
mcupka mcupka is offline
 

eXpert
  
Join Date: Jan 2013
Posts: 204
 

Default Re: Adding a new property to a category

Quote:
Originally Posted by tony_sologubov
Hi @mcupka,

There is an article that describes how to add new property to product in X-Cart 5.1 - 5.2:
https://devs.x-cart.com/basics/model_editing_page.html

The same principle works for editing category page in X-Cart 5.3.

Basically, you will only need to decorate \XLite\View\Model\Category class and define its constructor method as follows:

Code:
public function __construct(array $params = array(), array $sections = array()) { $this->schemaDefault['your_field'] = [] // your definition of the field parent::__construct($params, $sections); }

Please, let us know, if it helps.
That makes sense, but I'm trying to define a new property in the admin section as well, not just pull specific default X-Cart fields onto a separate page as this demo seems to do.

I have a ticket in with support to see what they say now that I've seen a few examples, thought about it more, have a better understanding etc.. Perhaps a better way to word what I'm looking for is this:

I'm trying to place certain elements throughout the site and it'd be nice if there was a module where I could input text into a field, have it display as raw HTML (this can be set with |raw, I know), and call it anywhere I'd like. Basically a global 'variable'. Kind of like how the language fields and labels work. So instead of creating a module for every small task, I could manage multiple edits on the site with this 1 module.

So then I'd basically just be editing .twig files to use the 'variable' into the custom HTML with {{ customlabel_1 }} to let's say "Hello world". {{customlabel_2}} says "Hey there", etc. Could place 1 in the header, 1 in footer, wherever I want within the .twig files really. Would give designers and developers a lot more flexibility and efficiency. More complex tweaks would of course require a custom module.
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:28 PM.

   

 
X-Cart forums © 2001-2020