View Single Post
  #1  
Old 05-11-2018, 07:15 AM
 
Soptareanu @Alex Soptareanu @Alex is offline
 

Advanced Member
  
Join Date: Apr 2018
Posts: 39
 

Default Dealing with Complex Schema API

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.
__________________
Soptareanu Alex
Reply With Quote