adding stocklevel by PHP controller to new product
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
adding stocklevel by PHP controller to new product
Hi,
I've created a secured area where frontend users can add events (for which later places will be sold with aimeos). Now I want to synchronize it automatically with the Ameos shop, starting now with creating new aimeos product items by a controller. I managed it already partially (title, type and price are created), but now I'm struggling on how to create the stock. Creating the price is working, I tried the same principle for the stocklevel but this seems not to work. What am I making wrong?
TYPO3: 12.4.22
Aimeos: 24.4.2
PHP: 8.3
Thank you!!!
I've created a secured area where frontend users can add events (for which later places will be sold with aimeos). Now I want to synchronize it automatically with the Ameos shop, starting now with creating new aimeos product items by a controller. I managed it already partially (title, type and price are created), but now I'm struggling on how to create the stock. Creating the price is working, I tried the same principle for the stocklevel but this seems not to work. What am I making wrong?
Code: Select all
$config = Base::config((array) $this->settings);
// $context = \Aimeos\TYPO3\Utility\Helper::getContext();
$context = \Aimeos\Aimeos\Base::context($config);
$productManager = MShop::create($context, 'product');
$product = $productManager->create();
$product->setCode($event->getUid()); // Eindeutiger Produktcode
$product->setLabel($event->getTitle()); // Produktname
$product->setType('event'); // Produkttyp
// Create price (is working)
$priceManager = MShop::create($context, 'price');
$price = $priceManager->create()->setValue($event->getKosten())->setCurrencyId('EUR');
// Add price to product
$product->addListItem( 'price', $productManager->createListItem(), $price );
// Create stock
$stockManager = MShop::create($context, 'stock');
$stock = $stockManager->create()->setProductId($event->getUid())->setType( 'default' )->setStockLevel($event->getTeilnehmerzahl());
$stockManager->save( $stock );
// Produkt speichern
$product->setModified();
$productManager->save($product);
Aimeos: 24.4.2
PHP: 8.3
Thank you!!!
Re: adding stocklevel by PHP controller to new product
Saving stock needs the product ID, not your event ID and you need to save the product before saving the stock item.
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
Re: adding stocklevel by PHP controller to new product
Thank you very much! That was the solution.