How to create catalogManager inside laravel console command ?
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!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
How to create catalogManager inside laravel console command ?
How to create catalogManager inside laravel console command ?
Post by MikaelNazarenko » 06 Sep 2019, 08:20
Hi my friends,
My environment is the following:
Laravel Framework 5.8.26
aimeos-laravel 2019.07
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1
I am writing laravel console command: app/Console/Commands/ImportProducts.php
And then I got the following error:
Also I have extended catalog manager: ext/labor/admin/jqadm/src/Catalog/Manager/Catalog.php
And config looks like:
If I comment the config it works!
I also have extended product manager and there it is working. But product manager constructor requires another argument - \Aimeos\MShop\Context\Item\Iface
Seems I extended something wrong.. I hope somebody may help me and it will be faster than I figure out it by myself..
Thank you all for the help!
Post by MikaelNazarenko » 06 Sep 2019, 08:20
Hi my friends,
My environment is the following:
Laravel Framework 5.8.26
aimeos-laravel 2019.07
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1
I am writing laravel console command: app/Console/Commands/ImportProducts.php
Code: Select all
$context = $this->getLaravel()->make(\Aimeos\Shop\Base\Context::class)->get( false, 'command' );
$context->setEditor( 'aimeos:account' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$localeItem = $localeManager->bootstrap( 'default', '', '', false );
$context->setLocale( $localeItem );
$catalogManager = \Aimeos\MShop::create( $context, 'catalog' );
Code: Select all
Argument 1 passed to Aimeos\MShop\Catalog\Manager\Catalog::__construct() must implement interface Aimeos\MShop\Common\Manager\Iface, instance of Aimeos\MShop\Context\Item\Standard given, called in /var/www/schmuck/vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Common/Factory/Base.php on line 151
Code: Select all
<?php
namespace Aimeos\MShop\Catalog\Manager;
class Catalog extends \Aimeos\MShop\Common\Manager\Decorator\Depth
{
public function __construct(\Aimeos\MShop\Common\Manager\Iface $manager, \Aimeos\MShop\Context\Item\Iface $context)
{
parent::__construct($manager, $context);
}
}
Code: Select all
'mshop' => [
'catalog' => [
'manager' => [
'name' => 'Catalog'
]
],
]
If I comment the config it works!
I also have extended product manager and there it is working. But product manager constructor requires another argument - \Aimeos\MShop\Context\Item\Iface
Seems I extended something wrong.. I hope somebody may help me and it will be faster than I figure out it by myself..
Thank you all for the help!
Re: How to create catalogManager inside laravel console command ?
You have to extend you new catalog class from \Aimeos\MShop\Catalog\Manager\Standard, not from the decorator
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Thank you ! This is my extended catalog item:
I have added few fields to catalog table. But it is different with product class. Here is some node.. How can I implement my setters and getters for new fields ? Should I modify this node or ?
Thank you a lot!
Code: Select all
<?php
namespace Aimeos\Admin\JQAdm\Catalog\Item;
/**
* Class Standard
* @package Aimeos\Admin\JQAdm\Product\Item
*
* @property string $id_product
*/
class Standard extends \Aimeos\MShop\Catalog\Item\Standard
{
private $node;
public function __construct(\Aimeos\MW\Tree\Node\Iface $node, $children = [], $listItems = [], $refItems = [])
{
parent::__construct($node, $children, $listItems, $refItems);
$this->node = $node;
}
}
I have added few fields to catalog table. But it is different with product class. Here is some node.. How can I implement my setters and getters for new fields ? Should I modify this node or ?
Thank you a lot!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Ah I see there are implemented magic methods _set and _get )) it must work 

Re: How to create catalogManager inside laravel console command ?
In the next version it will be much simpler to add additional columns/properties:
post9149.html#p9149
post9149.html#p9149
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Ok, but this version is not available yet ?
And now I have another problem.
I extended \Aimeos\MShop\Catalog\Item\Standard :
But in some cases constructor receives \Aimeos\MW\Tree\Node\DBNestedSet as $node. And here I get problem... (
The error is 'Call to undefined method Aimeos\\MW\\Tree\\Node\\DBNestedSet::getIdGroup()' it appears on admin panel on Catalog page on ajax request
The following code makes constructor to receive DBNestedSet
And now I have another problem.
I extended \Aimeos\MShop\Catalog\Item\Standard :
Code: Select all
<?php
namespace Aimeos\Admin\JQAdm\Catalog\Item;
/**
* Class Standard
* @package Aimeos\Admin\JQAdm\Product\Item
*
* @property string $id_product
*/
class Standard extends \Aimeos\MShop\Catalog\Item\Standard
{
private $node;
public function __construct(\Aimeos\MW\Tree\Node\Iface $node, $children = [], $listItems = [], $refItems = [])
{
// \Aimeos\MW\Tree\Node\DBNestedSet::class
parent::__construct($node, $children, $listItems, $refItems);
$this->node = $node;
}
public function getIdGroup()
{
return $this->node->getIdGroup();
}
public function setIdGroup($idGroup)
{
$this->node->setIdGroup($idGroup);
return $this;
}
public function fromArray(array &$list, $private = false)
{
$item = parent::fromArray($list);
foreach ($list as $key => $value) {
switch ($key) {
case 'catalog.id_group':
$item->setIdGroup($value);
break;
}
}
return $item;
}
public function toArray( $private = false )
{
$list = parent::toArray( $private );
if( $private === true ) {
$list['catalog.id_group'] = $this->getIdGroup();
}
dd($list);
return $list;
}
}
But in some cases constructor receives \Aimeos\MW\Tree\Node\DBNestedSet as $node. And here I get problem... (
The error is 'Call to undefined method Aimeos\\MW\\Tree\\Node\\DBNestedSet::getIdGroup()' it appears on admin panel on Catalog page on ajax request
The following code makes constructor to receive DBNestedSet
Code: Select all
$catalog = $catalogManager->createItem();
$catalog->setIdGroup($id_group);
$catalog->setLabel($label);
$catalogManager->saveItem($catalog);
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Hmmm, what is the magic ? ) __set method must be called in Aimeos\MW\Tree\Node\Standard but it is not called. But DBNestedSet extends the Aimeos\MW\Tree\Node\Standard . ..
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Aaaaaaaaah, sorry )) I am so stupid today )) I need just set the property $this->node->id_group = $idGroup; but not to call method)
Thank you a lot!
Thank you a lot!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Now I have another real problem. I have added markers to insert query to catalog id_group filed. And now I can't understand how to extend the bindings ? Because they are in the Aimeos\MW\Tree\Manager\DBNestedSet insertNode method
Seems it is hardcoded ?(
Seems it is hardcoded ?(
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create catalogManager inside laravel console command ?
Code: Select all
/**
* @param \Aimeos\MShop\Catalog\Item\Iface $item
* @param null $parentId
* @param null $refId
* @return \Aimeos\MShop\Catalog\Item\Iface
* @throws \Exception
*/
public function insertItem( \Aimeos\MShop\Catalog\Item\Iface $item, $parentId = null, $refId = null )
{
$this->begin();
$this->lock();
try
{
$node = $item->getNode();
$siteid = $this->getContext()->getLocale()->getSiteId();
$this->createTreeManager( $siteid )->insertNode( $node, $parentId, $refId );
$this->updateUsage( $node->getId(), $item, true );
$this->unlock();
$this->commit();
}
catch( \Exception $e )
{
$this->unlock();
$this->rollback();
throw $e;
}
$item = $this->saveListItems( $item, 'catalog' );
return $this->saveChildren( $item );
}
/**
* Updates the usage information of a node.
*
* @param string $id Id of the record
* @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item
* @param boolean $case True if the record shoud be added or false for an update
* @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls
*/
private function updateUsage( $id, \Aimeos\MShop\Catalog\Item\Iface $item, $case = false )
{
$date = date( 'Y-m-d H:i:s' );
$context = $this->getContext();
$dbm = $context->getDatabaseManager();
$dbname = $this->getResourceName();
$conn = $dbm->acquire( $dbname );
try
{
$siteid = $context->getLocale()->getSiteId();
if( $case !== true )
{
/** mshop/catalog/manager/standard/update-usage/mysql
* Updates the config, editor and mtime value of an updated record
*
* @see mshop/catalog/manager/standard/update-usage/ansi
*/
/** mshop/catalog/manager/standard/update-usage/ansi
* Updates the config, editor and mtime value of an updated record
*
* Each record contains some usage information like when it was
* created, last modified and by whom. These information are part
* of the catalog items and the generic tree manager doesn't care
* about this information. Thus, they are updated after the tree
* manager saved the basic record information.
*
* The SQL statement must be a string suitable for being used as
* prepared statement. It must include question marks for binding
* the values from the catalog item to the statement before they are
* sent to the database server. The order of the columns must
* correspond to the order in the method using this statement,
* so the correct values are bound to the columns.
*
* The SQL statement should conform to the ANSI standard to be
* compatible with most relational database systems. This also
* includes using double quotes for table and column names.
*
* @param string SQL statement for updating records
* @since 2014.03
* @category Developer
* @see mshop/catalog/manager/standard/delete/ansi
* @see mshop/catalog/manager/standard/get/ansi
* @see mshop/catalog/manager/standard/insert/ansi
* @see mshop/catalog/manager/standard/newid/ansi
* @see mshop/catalog/manager/standard/search/ansi
* @see mshop/catalog/manager/standard/search-item/ansi
* @see mshop/catalog/manager/standard/count/ansi
* @see mshop/catalog/manager/standard/move-left/ansi
* @see mshop/catalog/manager/standard/move-right/ansi
* @see mshop/catalog/manager/standard/update-parentid/ansi
* @see mshop/catalog/manager/standard/insert-usage/ansi
*/
$path = 'mshop/catalog/manager/standard/update-usage';
}
else
{
/** mshop/catalog/manager/standard/insert-usage/mysql
* Updates the config, editor, ctime and mtime value of an inserted record
*
* @see mshop/catalog/manager/standard/insert-usage/ansi
*/
/** mshop/catalog/manager/standard/insert-usage/ansi
* Updates the config, editor, ctime and mtime value of an inserted record
*
* Each record contains some usage information like when it was
* created, last modified and by whom. These information are part
* of the catalog items and the generic tree manager doesn't care
* about this information. Thus, they are updated after the tree
* manager inserted the basic record information.
*
* The SQL statement must be a string suitable for being used as
* prepared statement. It must include question marks for binding
* the values from the catalog item to the statement before they are
* sent to the database server. The order of the columns must
* correspond to the order in the method using this statement,
* so the correct values are bound to the columns.
*
* The SQL statement should conform to the ANSI standard to be
* compatible with most relational database systems. This also
* includes using double quotes for table and column names.
*
* @param string SQL statement for updating records
* @since 2014.03
* @category Developer
* @see mshop/catalog/manager/standard/delete/ansi
* @see mshop/catalog/manager/standard/get/ansi
* @see mshop/catalog/manager/standard/insert/ansi
* @see mshop/catalog/manager/standard/newid/ansi
* @see mshop/catalog/manager/standard/search/ansi
* @see mshop/catalog/manager/standard/search-item/ansi
* @see mshop/catalog/manager/standard/count/ansi
* @see mshop/catalog/manager/standard/move-left/ansi
* @see mshop/catalog/manager/standard/move-right/ansi
* @see mshop/catalog/manager/standard/update-parentid/ansi
* @see mshop/catalog/manager/standard/update-usage/ansi
*/
$path = 'mshop/catalog/manager/standard/insert-usage';
}
$stmt = $conn->create( $this->getSqlConfig( $path ) );
$stmt->bind( 1, json_encode( $item->getConfig() ) );
$stmt->bind( 2, $date ); // mtime
$stmt->bind( 3, $context->getEditor() );
$stmt->bind( 4, $item->getTarget() );
$stmt->bind( 5, $item->getIdGroup() );
if( $case !== true )
{
$stmt->bind( 6, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
$stmt->bind( 7, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
}
else
{
$stmt->bind( 6, $date ); // ctime
$stmt->bind( 7, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
$stmt->bind( 8, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
}
$stmt->execute()->finish();
$dbm->release( $conn, $dbname );
}
catch( \Exception $e )
{
$dbm->release( $conn, $dbname );
throw $e;
}
return $this;
}