xbenjii Posted September 17, 2014 Share Posted September 17, 2014 How hard would this be to implement? Would it require editing the core files or can I do it from within a module? 1 Link to comment Share on other sites More sharing options...
hpar Posted September 17, 2014 Share Posted September 17, 2014 You can override the core files in a module. Link to comment Share on other sites More sharing options...
xbenjii Posted September 17, 2014 Author Share Posted September 17, 2014 You can override the core files in a module. What approach should I take, is there any documentation on this? Link to comment Share on other sites More sharing options...
hpar Posted September 18, 2014 Share Posted September 18, 2014 About overriding files: http://doc.prestashop.com/display/PS16/Overriding+default+behaviors About adding a new resource: read the code of the core files exposing resources The data is provided by the core files (like Product.php, Cart.php, ...) as PHP arrays and transformed into XML ( or JSON) in /classes/webservice/WebserviceOutput*.php There is also a static list of the resources available in WebserviceRequest::getResources() Link to comment Share on other sites More sharing options...
xbenjii Posted September 18, 2014 Author Share Posted September 18, 2014 (edited) About overriding files: http://doc.prestashop.com/display/PS16/Overriding+default+behaviors About adding a new resource: read the code of the core files exposing resources The data is provided by the core files (like Product.php, Cart.php, ...) as PHP arrays and transformed into XML ( or JSON) in /classes/webservice/WebserviceOutput*.php There is also a static list of the resources available in WebserviceRequest::getResources() Thanks for the help. So from what I understand so far I need to extend the WebServiceRequestCore class from within a module override to add the new resource. So far I have: /modules/totLoyaltyAdvanced/override/classes/webservice/WebserviceRequest.php class WebserviceRequest extends WebserviceRequestCore { public static function getResources(){ $resources = parent::getResources(); $resources['loyalty'] = array('description' => 'Loyalty management for products', 'class' => 'LoyaltyAPI'); ksort($resources); return $resources; } } /modules/totLoyaltyAdvanced/override/classes/LoyaltyAPI.php class LoyaltyAPICore extends ObjectModel { public $id_product; public $loyalty; public $date_begin = '0000-00-00'; public $date_finish = '0000-00-00'; public static $definition = array( 'table' => 'totloyaltyadvanced', 'primary' => 'id', 'fields' => array( 'id_product' => array('type' => self::TYPE_INT, 'required' => true), 'loyalty' => array('type' => self::TYPE_STRING, 'required' => true), 'date_begin' => array('type' => self::TYPE_STRING), 'date_finish' => array('type' => self::TYPE_STRING) ) ); protected $webserviceParameters = array(); } But for some reason PrestaShop doesn't seem to be invoking the overridden classes. I have deleted /cache/class_index.php but it still isn't working. Any ideas? Reinstalled module and seems to be working. Only problem is removing the module brings up an error, which I have opened as a bug report here. Edited September 18, 2014 by xbenjii (see edit history) 1 Link to comment Share on other sites More sharing options...
karcharoth Posted November 15, 2019 Share Posted November 15, 2019 (edited) Your were extending ObjectModel class with a non-existing class (LoyaltyAPICore) - so the override could not be created. You should extend ObjectModel class, like this: On 9/18/2014 at 12:07 PM, xbenjii said: /modules/totLoyaltyAdvanced/override/classes/webservice/WebserviceRequest.php class WebserviceRequest extends WebserviceRequestCore { public static function getResources(){ $resources = parent::getResources(); $resources['loyalty'] = array('description' => 'Loyalty management for products', 'class' => 'ObjectModel'); ksort($resources); return $resources; } } /modules/totLoyaltyAdvanced/override/classes/ObjectModel.php class ObjectModel extends ObjectModelCore { public $id_product; public $loyalty; public $date_begin; public $date_finish; public function __construct($id = null, $id_lang = null, $id_shop = null) { self::$definition['table'] = 'totloyaltyadvanced'; self::$definition['primary'] = 'id'; self::$definition['fields']['id_product'] = array('type' => self::TYPE_INT, 'required' => true); self::$definition['fields']['loyalty'] = array('type' => self::TYPE_STRING, 'required' => true); self::$definition['fields']['date_begin'] = array('type' => self::TYPE_STRING); self::$definition['fields']['date_finish'] = array('type' => self::TYPE_STRING); parent::__construct($id, $id_lang, $id_shop); } } It should work fine now. Tested on PS 1.6.1.20. Edited November 15, 2019 by karcharoth (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now