When extending jqadm attribute template It duplicate the page rendered
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- ahmed31916
- Advanced
- Posts: 148
- Joined: 14 Apr 2022, 12:15
When extending jqadm attribute template It duplicate the page rendered
Hello,
When extending jqadm attribute template src (vendor\aimeos\ai-admin-jqadm\src\Admin\JQAdm\Attribute\Standard.php), It duplicate the page rendered as shown in the attached image.
This is the code:
Maybe it is rendered twice (one from the extending class, and other from the vendor class).
When extending jqadm attribute template src (vendor\aimeos\ai-admin-jqadm\src\Admin\JQAdm\Attribute\Standard.php), It duplicate the page rendered as shown in the attached image.
This is the code:
Code: Select all
namespace Aimeos\Admin\JQAdm\Common\Decorator;
class AttributeStandard
extends \Aimeos\Admin\JQAdm\Common\Decorator\Base
implements \Aimeos\Admin\JQAdm\Common\Decorator\Iface
{
...
}
- Attachments
-
- Screenshot 2022-09-06 145124.png (109.83 KiB) Viewed 1254 times
Re: When extending jqadm attribute template It duplicate the page rendered
What's the implementation of the decorator class (what you've replaced by "...")?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- ahmed31916
- Advanced
- Posts: 148
- Joined: 14 Apr 2022, 12:15
Re: When extending jqadm attribute template It duplicate the page rendered
this code:
Code: Select all
public function data( \Aimeos\Base\View\Iface $view ) : \Aimeos\Base\View\Iface
{
$all_makes = \Aimeos\Controller\Frontend::create( $this->context(), 'attribute' )
->compare( '==', 'attribute.type', 'Make' )
->sort( 'position' )->slice( 0, 10000 )->search();
$view->all_makes = $all_makes;
$view->itemSubparts = $this->getSubClientNames();
$view->itemTypes = $this->getTypeItems();
return $view;
}
public function batch() : ?string
{
return $this->batchBase( 'attribute' );
}
public function get() : ?string
{
$view = $this->object()->data( $this->view() );
try
{
if( ( $id = $view->param( 'id' ) ) === null )
{
$msg = $this->context()->translate( 'admin', 'Required parameter "%1$s" is missing' );
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, 'id' ) );
}
$manager = \Aimeos\MShop::create( $this->context(), 'attribute' );
$view->item = $manager->get( $id, $this->getDomains() );
$view->itemData = $this->toArray( $view->item );
$view->itemBody = parent::get();
}
catch( \Exception $e )
{
$this->report( $e, 'get' );
}
return $this->render( $view );
}
public function save() : ?string
{
$view = $this->view();
$manager = \Aimeos\MShop::create( $this->context(), 'attribute' );
$manager->begin();
try
{
$item = $this->fromArray( $view->param( 'item', [] ) );
$view->item = $item->getId() ? $item : $manager->save( $item );
$view->itemBody = parent::save();
$manager->save( clone $view->item );
$manager->commit();
if(request()->make !== null){
$attr_model_id = request()->item['attribute.id'] ?? $view->item->getId();
$attr_model_id_check = AttributeList::where('parentid', $attr_model_id)->first();
}
return $this->redirect( 'attribute', $view->param( 'next' ), $view->item->getId(), 'save' );
}
catch( \Exception $e )
{
$manager->rollback();
$this->report( $e, 'save' );
}
return $this->create();
}
public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
{
return $this->createSubClient( 'attribute/' . $type, $name );
}
protected function getDomains() : array
{
return $this->context()->config()->get( 'admin/jqadm/attribute/domains', [] );
}
protected function getSubClientNames() : array
{
return $this->context()->config()->get( 'admin/jqadm/attribute/subparts', [] );
}
protected function getTypeItems() : \Aimeos\Map
{
$typeManager = \Aimeos\MShop::create( $this->context(), 'attribute/type' );
$search = $typeManager->filter( true )->slice( 0, 10000 );
$search->setSortations( [$search->sort( '+', 'attribute.type.label' )] );
return $typeManager->search( $search );
} protected function fromArray( array $data ) : \Aimeos\MShop\Attribute\Item\Iface
{
$manager = \Aimeos\MShop::create( $this->context(), 'attribute' );
if( isset( $data['attribute.id'] ) && $data['attribute.id'] != '' ) {
$item = $manager->get( $data['attribute.id'], $this->getDomains() );
} else {
$item = $manager->create();
}
$item->fromArray( $data, true );
return $item;
}
protected function toArray( \Aimeos\MShop\Attribute\Item\Iface $item, bool $copy = false ) : array
{
$data = $item->toArray( true );
if( $copy === true )
{
$data['attribute.siteid'] = $this->context()->locale()->getSiteId();
$data['attribute.code'] = $data['attribute.code'] . '_' . substr( md5( microtime( true ) ), -5 );
$data['attribute.id'] = '';
}
return $data;
}
protected function render( \Aimeos\Base\View\Iface $view ) : string
{
$tplconf = 'admin/jqadm/attribute/template-item';
$default = 'attribute/item';
return $view->render( $view->config( $tplconf, $default ) );
}
Re: When extending jqadm attribute template It duplicate the page rendered
You've copied the code from the attribute JQAdm class more or less into your new decorator and this is wrong. A decorator should only add additional or modify existing data and must only contain code for that.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star