How can i add product to specific category from my own controller
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!
-
- Posts: 86
- Joined: 12 Jan 2019, 15:17
How can i add product to specific category from my own controller
How can i add product to specific category from my own controller
I m using aimeos 2019.10.*
Please guide how can i can do that in new version
Previously i was using this code to do that
$data = array(
'product' => array(
array(
'code' => $productCode,
'list-type' => 'default',
'list-position' => 0,
'list-config' => [],
'list-start' => null,
'list-end' => null,
'list-status' => 1
)
)
);
$this->addProducts($catalogItem->getId(), $data['product'], 'catalog');
and Add function is doing this:
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$productManager = \Aimeos\MShop::create($context, 'product');
$listManager = \Aimeos\MShop::create($context, $domain . '/lists');
$listItem = $listManager->createItem();
$listItem->setParentId($parentid);
$listItem->setDomain('product');
$codes = [];
foreach ($data as $entry) {
$codes[$entry['code']] = null;
}
$search = $productManager->createSearch()->setSlice(0, 0x7fffffff);
$search->setConditions($search->compare('==', 'product.code', array_keys($codes)));
$products = $productManager->searchItems($search);
foreach ($products as $product) {
$codes[$product->getCode()] = $product->getId();
}
foreach ($data as $entry) {
if (!isset($codes[$entry['code']])) {
throw new \RuntimeException(sprintf('No product for code "%1$s" found', $entry['code']));
}
$listItem->setId(null);
$listItem->setType(7);
$listItem->setDateStart($entry['list-start']);
$listItem->setDateEnd($entry['list-end']);
$listItem->setConfig($entry['list-config']);
$listItem->setPosition($entry['list-position']);
$listItem->setStatus($entry['list-status']);
$listItem->setRefId($codes[$entry['code']]);
$listManager->saveItem($listItem, false);
Thanks
I m using aimeos 2019.10.*
Please guide how can i can do that in new version
Previously i was using this code to do that
$data = array(
'product' => array(
array(
'code' => $productCode,
'list-type' => 'default',
'list-position' => 0,
'list-config' => [],
'list-start' => null,
'list-end' => null,
'list-status' => 1
)
)
);
$this->addProducts($catalogItem->getId(), $data['product'], 'catalog');
and Add function is doing this:
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$productManager = \Aimeos\MShop::create($context, 'product');
$listManager = \Aimeos\MShop::create($context, $domain . '/lists');
$listItem = $listManager->createItem();
$listItem->setParentId($parentid);
$listItem->setDomain('product');
$codes = [];
foreach ($data as $entry) {
$codes[$entry['code']] = null;
}
$search = $productManager->createSearch()->setSlice(0, 0x7fffffff);
$search->setConditions($search->compare('==', 'product.code', array_keys($codes)));
$products = $productManager->searchItems($search);
foreach ($products as $product) {
$codes[$product->getCode()] = $product->getId();
}
foreach ($data as $entry) {
if (!isset($codes[$entry['code']])) {
throw new \RuntimeException(sprintf('No product for code "%1$s" found', $entry['code']));
}
$listItem->setId(null);
$listItem->setType(7);
$listItem->setDateStart($entry['list-start']);
$listItem->setDateEnd($entry['list-end']);
$listItem->setConfig($entry['list-config']);
$listItem->setPosition($entry['list-position']);
$listItem->setStatus($entry['list-status']);
$listItem->setRefId($codes[$entry['code']]);
$listManager->saveItem($listItem, false);
Thanks
Re: How can i add product to specific category from my own controller
This looks fishy:
The rest should be OK because there have been no changes in that area.
Code: Select all
$listItem->setType(7);
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
-
- Posts: 86
- Joined: 12 Jan 2019, 15:17
Re: How can i add product to specific category from my own controller
what should be in thisaimeos wrote: ↑16 Dec 2019, 18:40 This looks fishy:The rest should be OK because there have been no changes in that area.Code: Select all
$listItem->setType(7);
$listItem->setType(?)
thanks
Re: How can i add product to specific category from my own controller
It should be either "default" or "promotion".
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
-
- Posts: 86
- Joined: 12 Jan 2019, 15:17