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

Working with ItemsList

 
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-02-2018, 03:42 AM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default 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.
__________________
Soptareanu Alex
Reply With Quote
  #2  
Old 05-02-2018, 06:43 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default 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.
__________________
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
  #3  
Old 05-02-2018, 07:12 AM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default Re: Working with ItemsList

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;
Attached Thumbnails
Click image for larger version

Name:	Capture_1.PNG
Views:	803
Size:	20.5 KB
ID:	5137  Click image for larger version

Name:	Capture_2.PNG
Views:	818
Size:	12.9 KB
ID:	5138  
__________________
Soptareanu Alex
Reply With Quote
  #4  
Old 05-03-2018, 04:24 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default 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
__________________
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

The following user thanks tony_sologubov for this useful post:
Soptareanu @Alex (05-03-2018)
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)



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 03:20 PM.

   

 
X-Cart forums © 2001-2020