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 form to new order details tab (https://forum.x-cart.com/showthread.php?t=72551)

Roman Prisiazniuk 08-09-2015 03:57 AM

Adding form to new order details tab
 
I need to create following module on admin page:
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?
Here is what I write in XLite\Module\Romas\ProductActivation\Model\OrderIt emActivation.php:
PHP Code:

<?php
namespace XLite\Module\Romas\ProductActivation\Model;

class 
OrderItemActivation extends \XLite\Model\Base\I18n
{
    
/**
     * OrderItemActivation unique ID
     *
     * @var integer
     *
     * @Id
     * @GeneratedValue (strategy="AUTO")
     * @Column         (type="integer", options={ "unsigned": true })
     */
    
protected $activation_id;

    
/**
     * OrderItemActivationn order items
     *
     * @Column         (type="integer", options={ "unsigned": true })
     */
    
protected $order_item_id;

    
/**
     * OrderItemActivation creation timestamp
     *
     * @var integer
     *
     * @Column (type="integer")
     */
    
protected $date;

    
/**
     * OrderItemActivation credit
     *
     * @var integer
     *
     * @Column (type="integer")
     */
    
protected $credit;

    
/**
     * OrderItemActivation Code
     *
     * @var string
     *
     * @Column (type="string", length=255, nullable=true)
     */
    
protected $activation_code;

    
/**
     * OrderItemActivation ip address
     *
     * @var string
     *
     * @Column (type="string", length=255, nullable=true)
     */
    
protected $ip_address;
}

is class OrderItemActivation extends \XLite\Model\Base\I18n is right?
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)?
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

Roman Prisiazniuk 08-10-2015 03:09 AM

Re: Adding form to new order details tab
 
Also I need to add OneToMany relation from OrderItem to OrderItemActivation entity, as I understand I must create decorator

PHP Code:

<?php
    
namespace XLite\Module\Romas\ProductActivation\Model;

    abstract class 
OrderItem extends \XLite\Model\OrderItem implements \XLite\Base\IDecorator
    
{
        
/**
         *
         * @var \Doctrine\Common\Collections\Collection
         *
         * @OneToMany (targetEntity="XLite\Module\Romas\ProductActivation\Model\OrderItemActivation", mappedBy="object", cascade={"all"})
         */
        
protected $productActivations;
    }


Please tell me what should I write in @OneToMany section: how can I set what column in OrderItems table to add?

qualiteam 08-16-2015 11:41 PM

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.

qualiteam 08-16-2015 11:45 PM

Re: Adding form to new order details tab
 
By the way, if your model don't have multilingual fields, you can extend it from \XLite\Model\AEntity class instead of \XLite\Model\Base\I18n (and the repository class from \XLite\Model\Repo\ARepo instead of \XLite\Model\Repo\Base\I18n).

If you need multilingual fields, extend the base model class from \XLite\Model\Base\I18n and put these fields into extra [BaseModelClass]Translation class.


All times are GMT -8. The time now is 01:17 PM.

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