Может кто работал с этой CMS? Документация очень слабая, в интернет информация стремится к нулю. Прикрепляю функцию с тестовыми данными. Товар создаётся, атрибут, вариант товара. Но то в админке в вариациях ничего нет, даже вкладка не появляется. Буду рад любой обратной связи. Спасибо
public function storeProduct($vendorSiteId, $productData, $variants = null)
{
$context = app('aimeos.context')->get();
$productManager = \Aimeos\MShop::create($context, 'product');
$attributeManager = \Aimeos\MShop::create($context, 'attribute');
$listManager = \Aimeos\MShop::create($context, 'product/lists');
/** === 1. Родительский товар === */
$parentCode = 'parent-123';
try {
$parent = $productManager->find($parentCode);
}catch (\Exception $exception){
$parent = $productManager->create();
$parent->setCode($parentCode);
$parent->setLabel('Футболка');
$parent->setType('selection');
$parent->setStatus(1);
$parent->set('variant', true);
$parent = $productManager->save($parent);
}
/** === 2. Атрибут (цвет) === */
$colorCode = 'color-red';
$colorType = 'color';
$filter = $attributeManager->filter()
->add('attribute.code', '==', $colorCode)
->add('attribute.type', '==', $colorType);
$colorItems = $attributeManager->search($filter);
if (count($colorItems) > 0) {
$colorRed = $colorItems->first();
} else {
$colorRed = $attributeManager->create();
$colorRed->setCode($colorCode);
$colorRed->setLabel('Red');
$colorRed->setType($colorType);
$colorRed->setDomain('product');
$colorRed = $attributeManager->save($colorRed);
}
/** === 3. Вариант товара === */
$variantCode = 'parent-123-red-m';
try {
$variant = $productManager->find($variantCode);
}catch (\Exception $exception){
$variant = $productManager->create();
$variant->setCode($variantCode);
$variant->setLabel('Футболка Красная M');
$variant->setType('article');
$variant->setStatus(1);
$variant->set('price', [
['currencyid' => 'RUB', 'value' => 1500]
]);
}
$variant = $productManager->save($variant);
// Привязка атрибута цвета
$variant->getRefItems()->add($colorRed->setType('color'), 'attribute');
$variant = $productManager->save($variant);
$listItemExists = MshopProductList::where('parentid', $parent->getId())
->where('siteid', '1.')
->where('refid', $variant->getId())
->where('domain', 'product')
->where('type', 'default')
->first();
if (!$listItemExists) {
$listItem = $listManager->create()
->setParentId($parent->getId()) // родитель
->set('refid', $variant->getId()) // дочерний
->set('domain', 'product')
->set('type', 'default') // связь «default»
->set('position', 0);
$listManager->save($listItem);
}
}