@
Alex,
You should try to implement getAllowedEntityClasses() method as follows:
Code:
protected function getAllowedEntityClasses()
{
$return = parent::getAllowedEntityClasses();
$return['XLite\Module\Tony\RestApiComplexSchema\Model\DemoEntity'] = 'XLite\Module\Tony\RestApiComplexSchema\Core\Schema\Complex\DemoEntity';
$return['XLite\Module\ProductVariant\Model\ProductVariant'] = 'XLite\Module\Tony\RestApiComplexSchema\Core\Schema\Complex\ProductVariant';
return $return;
}
In other words, the key of return array must be name of model class and the value must be name of the class that implements the complex schema.
Please, let me know if it helps.
Quote:
Originally Posted by Soptareanu @Alex
I want to create a complex schema for ProductVariant entity. I follow the implementation of Tony-Restapicomplex module but i got an exception such as :
There is no model schema for that class.
This is my schema :
PHP Code:
<?php
namespace XLite\Module\Tony\RestApiComplexSchema\Core\Schema\Complex;
/**
* Product schema
*/
class ProductVariant implements \XLite\Module\XC\RESTAPI\Core\Schema\Complex\IModel
{
/**
* Convert model
*
* @param \XLite\Model\AEntity $model Entity
* @param boolean $withAssociations Convert with associations
*
* @return array
*/
public function convertModel(\XLite\Model\AEntity $model, $withAssociations)
{
return [
'id' => 'My custom field on complex schema !',
];
}
public function prepareInput(array $data)
{
return [ true, $data ];
}
/**
* Preload data
*
* @param \XLite\Model\AEntity $entity Product
* @param array $data Data
*
* @return void
*/
public function preloadData(\XLite\Model\AEntity $entity, array $data)
{
}
}
And this is the Complex.php file that decorate \XLite\Module\XC\RESTAPI\Core\Schema\Complex :
PHP Code:
<?php
namespace XLite\Module\Tony\RestApiComplexSchema\Core\Schema;
class Complex extends \XLite\Module\XC\RESTAPI\Core\Schema\Complex implements \XLite\Base\IDecorator
{
protected function getAllowedEntityClasses()
{
$return = parent::getAllowedEntityClasses();
$return['XLite\Module\Tony\RestApiComplexSchema\Model\DemoEntity'] = 'XLite\Module\Tony\RestApiComplexSchema\Core\Schema\Complex\DemoEntity';
$return['XLite\Module\Tony\RestApiComplexSchema\Model\ProductVariant'] = 'XLite\Module\ProductVariant\Model\ProductVariant';
return $return;
}
}
What is wrong ?! The demo-entity works very well. But ProductVariant not.
|