X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Working with ItemsList (https://forum.x-cart.com/showthread.php?t=76211)

Soptareanu @Alex 05-02-2018 03:42 AM

Working with ItemsList
 
I have an itemsList table. I want to save in my entity a field with value of param. such as admin.php?target=returned_products&order=<Some Value of Param>. For that task I put in class that defined the table this method :
/**
* Create entity
*
* @return \XLite\Model\AEntity
*/
protected function createEntity()
{
$entity = parent::createEntity();
$entity->setFormId(\XLite\Core\Request::getInstance()->order);

return $entity;
}
But stil didn't work and throw me error :
An exception occurred while executing 'INSERT INTO xc_retur_product (position, enabled, form_id, code, qty) VALUES (?, ?, ?, ?, ?)' with params [0, 1, null, "<Value>", "<Value>"]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'form_id' cannot be null.
What method do i need in order to set this field before i persist in database ? I don't want to show in table that particular column.

tony_sologubov 05-02-2018 06:43 AM

Re: Working with ItemsList
 
Hi @Alex,

First of all, do you even need this 'form_id' param in your model? Maybe you can just remove it.

Otherwise, it looks like the problem is not while creating an entity, but rather while updating it. Can it be that your ItemsList has 'form_id' in defineColumns() method, but when the request is submitted, 'form_id' is not there?

Tony

Quote:

Originally Posted by Soptareanu @Alex
I have an itemsList table. I want to save in my entity a field with value of param. such as admin.php?target=returned_products&order=<Some Value of Param>. For that task I put in class that defined the table this method :
/**
* Create entity
*
* @return \XLite\Model\AEntity
*/
protected function createEntity()
{
$entity = parent::createEntity();
$entity->setFormId(\XLite\Core\Request::getInstance()->order);

return $entity;
}
But stil didn't work and throw me error :
An exception occurred while executing 'INSERT INTO xc_retur_product (position, enabled, form_id, code, qty) VALUES (?, ?, ?, ?, ?)' with params [0, 1, null, "<Value>", "<Value>"]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'form_id' cannot be null.
What method do i need in order to set this field before i persist in database ? I don't want to show in table that particular column.


Soptareanu @Alex 05-02-2018 07:12 AM

Re: Working with ItemsList
 
2 Attachment(s)
Quote:

Originally Posted by tony_sologubov
Hi @Alex,

First of all, do you even need this 'form_id' param in your model? Maybe you can just remove it.

Otherwise, it looks like the problem is not while creating an entity, but rather while updating it. Can it be that your ItemsList has 'form_id' in defineColumns() method, but when the request is submitted, 'form_id' is not there?

Tony

Yes, I need this form_id, because i use it to fillter the list. In the URL i have a param order=<Value>. That value is coresponding with form_id, and show me a list of items with form_id = order. If I update the item it works very fine, but if i want to create a new one, i want that the form_id remain the same based on url param. I used \XLite\Core\Request::getInstance()->order;

tony_sologubov 05-03-2018 04:24 AM

Re: Working with ItemsList
 
Quote:

Originally Posted by Soptareanu @Alex
Yes, I need this form_id, because i use it to fillter the list. In the URL i have a param order=<Value>. That value is coresponding with form_id, and show me a list of items with form_id = order. If I update the item it works very fine, but if i want to create a new one, i want that the form_id remain the same based on url param. I used \XLite\Core\Request::getInstance()->order;


I see. Thanks for explanation.

The problem looks to be that 'order' param is not in POST request when you submit the ItemsList. It is in GET parameters when you open the page with ItemsList, but when the ItemsList's form is submitted, it is not there.

To add 'order' as a hidden input to your ItemsList's form, create the following method in your ItemsList class:

Code:

    protected function getFormParams()
    {
        return parent::getFormParams() + [
            'order' => \XLite\Core\Request::getInstance()->order
        ];
    }


Please, let me know if it helps.

Tony


All times are GMT -8. The time now is 07:11 AM.

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