Jump to content

override class product pour webservices


Recommended Posts

Je n'arrive pas à overrider la class product.php pour un webservice.

Si je modifie le core de la class product, j'arrive à faire ce que je veux. Je veux récuperer le tax_rate d'un produit par webservice (cela n'est pas implémenté dans le webservices products).

si je modifie la class product comme cela :

protected $webserviceParameters = array(
 'objectMethods' => array('add' => 'addWs', 'update' => 'updateWs'),
 'objectNodeNames' => 'products',
 'fields' => array(
  'id_manufacturer' => array('xlink_resource' => 'manufacturers'),
  'id_supplier' => array('xlink_resource' => 'suppliers'),
  'id_category_default' => array('xlink_resource' => 'categories'),
  'out_of_stock' => array('required' => true),
  'new' => array(),
  'cache_default_attribute' => array(),
  'id_default_image' => array('getter' => 'getCoverWs', 'setter' => 'setCoverWs', 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
  'id_default_combination' => array('getter' => 'getWsDefaultCombination', 'setter' => 'setWsDefaultCombination', 'xlink_resource' => array('resourceName' => 'combinations')),
  'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => false),
  'manufacturer_name' => array('getter' => 'getWsManufacturerName', 'setter' => false),
 protected	$webserviceParameters = array(
	'objectMethods' => array('add' => 'addWs', 'update' => 'updateWs'),
	'objectNodeNames' => 'products',
	'fields' => array(
		'id_manufacturer' => array('xlink_resource' => 'manufacturers'),
		'id_supplier' => array('xlink_resource' => 'suppliers'),
		'id_category_default' => array('xlink_resource' => 'categories'),
		'out_of_stock' => array('required' => true),
		'new' => array(),
		'cache_default_attribute' => array(),
		'id_default_image' => array('getter' => 'getCoverWs', 'setter' => 'setCoverWs', 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
		'id_default_combination' => array('getter' => 'getWsDefaultCombination', 'setter' => 'setWsDefaultCombination', 'xlink_resource' => array('resourceName' => 'combinations')),
		'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => false),
		'manufacturer_name' => array('getter' => 'getWsManufacturerName', 'setter' => false),	
		'tax_rate' => array('getter' => 'getWsTaxRate', 'setter' => false),
		),
  ),

j'ajoute cette ligne : 'tax_rate' => array('getter' => 'getWsTaxRate', 'setter' => false),

et ensuite j'ajoute cette fonction dans l'override de la classe product :

<?php
class Product extends ProductCore
{

public function getWsTaxRate()
{
 return Tax::getProductTaxRate($this->id, NULL);
}
}
?>

 

comme cela ça fonctionne. Mais comment faire pour ajouter dans $webserviceParameters le tax_rate sans modifier la class core product.php.

j'ai ésssayé de faire :

array_push($webserviceParameters['fields'],'tax_rate' => array('getter' => 'getWsTaxRate', 'setter' => false));

mais ça ne marche pas.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...