From last 2-3 days , I hitched in a problem , actually my problem was to create an entry in prestashop`s table(created by me) using webservices , but as we all know that , the webService of Prestashop includes only REST API which has very limited number of nodes(tables) for performing CRUD(Create/Read/Update/Delete) operations. I googled a lot for finding a solution, but found nothing.
Finally, I did it by reading codes of prestashop ,also by HIT n TRY method. Now , I want to share it with all of you .May be it will help someone like me n save his/her time. Here it is,
Table Information : (which we want to add in prestashop`s webservice)
Table Name : erp_product_merge Columns name : id , erp_product_id , prestashop_product_id , created_by. Primary key : id
PHP Code : [stextbox id=”info”]save this code as ‘ProductMerge.php’ in ‘~prestashop\override\classes’ folder.[/stextbox]
class ProductMergeCore extends ObjectModel { public $erp_product_id; public $prestashop_product_id; public $created_by ; public static $definition = array( 'table' => 'erp_product_merge', 'primary' => 'id', 'fields' => array( 'erp_product_id' => array('type' => self::TYPE_INT, 'required' => true), 'prestashop_product_id' => array('type' => self::TYPE_INT, 'required' => true), 'created_by' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 64), ), ); protected $webserviceParameters = array(); }
PHP Code : [stextbox id=”info”]save this code as ‘WebserviceRequest.php’ in ‘~prestashop\override\classes\webservice’ folder.[/stextbox]
<?php class WebserviceRequest extends WebserviceRequestCore { public static function getResources() { $resources=parent::getResources(); $resources['erp_product_merges'] = array('description' => 'Test Demo', 'class' => 'ProductMerge'); ksort($resources); return $resources; } }
Now , give the permissions to this resource from prestashop`s admin panel and try to perform CRUD operations on this resource via WebServices. Enjoy !!
[stextbox id=”warning”]Your opinions, comments and suggestions are important to keep the page updated and interesting. [/stextbox]
17 comments
You cannot have two primary keys in one table, can u elaborate you issue a little bit more ?
Thanks
I’m studying Prestashop’s development. And I trying to create a “third part” side application with react.js to catch Json data in the prestashop’s webservice. But I want to let the “customer” make login with his own account. With CRUD also.
in advance; Very thank you for your patience and attention.
Best Regards.
Michel Diz