View Single Post
  #3  
Old 08-16-2015, 11:41 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Adding form to new order details tab

Quote:
1. It must add new table OrderItemActivations to DB, as I understand if my module located in XLite\Module\Romas\ProductActivation I must add ProductActivation.php(with table schema) to XLite\Module\Romas\ProductActivation\Model folder, am I right?

Although the class name can be anything you want, it is recommended to name it as the table name. So, it makes sense to name the class OrderItemActivation instead of ProductActivation (so the file will be OrderItemActivation.php, not ProductActivation.php).

The path can be any too, but it is recommended to keep model entity classes inside the Model subdirectory.

You can check this article on creating custom models:
http://kb.x-cart.com/display/XDD/Understanding+Models

Quote:
Here is what I write in XLite\Module\Romas\ProductActivation\Model\OrderIt emActivation.php

You have missed the docblock with the class description. It should be something like this:
PHP Code:
/**
 * @Entity (repositoryClass="\XLite\Module\Romas\ProductActivation\Model\Repo\OrderItemActivation")
 * @Table  (name="order_item_activations")
 */
class OrderItemActivation extends \XLite\Model\Base\I18n
{
... 

And you need the \XLite\Module\Romas\ProductActivation\Model\Repo\O rderItemActivation class too (however, it can be an empty class extending \XLite\Model\Repo\Base\I18n).

Quote:
2. It must add a new tab to order details, I can make it following instructions http://kb.x-cart.com/display/XDD/Adding+tabs, but instead of decorating \XLite\Controller\Admin\Product I must decorate \XLite\Controller\Admin\Order class. But also tell me please how to create viewer class for this tab(where must it be located and how to connect this viewer class to template that is used for new tab)?

Please see how the two standard tabs ('info' and 'invoice') are added in the \XLite\Controller\Admin\Order controller class. You should decorate this class, add your tabs and add necessary View templates and classes.

Quote:
3. In created tab it must add a form which adds new record to ProductActivation table, how can I create such form, where should be a handler of this form and how should it look? Please clarify

This one will be a bit more complex. You need View\Model\OrderItemActivation class that will declare the form and a controller class that will handle your new actions and pass them to that "view model". Please use other \XLite\View\Model classes as the example.

Also, the X-Cart 5 SDK (http://kb.x-cart.com/display/XDD/X-Cart+SDK) has a script (devkit/macros/create-crud-list.php) that can automate the process of creating back-end pages for new entities. The script create a page with the list of new entities and a page for creating/editing a new entity.

Quote:
Originally Posted by Roman Prisiazniuk
Also I need to add OneToMany relation from OrderItem to OrderItemActivation entity, ...
Please tell me what should I write in @OneToMany section: how can I set what column in OrderItems table to add?


Yes, you should link OrderItem to OrdetItemActivation and back.

To add your relation to OrderItem class you should decorate it from your custom module (search for "IDecorator" at http://kb.x-cart.com/ for articles/examples).

Also, you can use \XLite\Model\Order and \XLite\Model\OrderItem as examples - these classes have the same relation that you need.
__________________
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