Upload media and attach to product from custom form
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Upload media and attach to product from custom form
Good day !
I have created custom pages for specific users. They can create products with attributes, prices, categories from that page. I used aimeos managers, everything works fine.
But i have an issue with media upload. This is my code.
How can i create previews, with sizes 240, 720, 800px, such as aimeos medias in database.
And generate media link same as aimeos do this.
Many thanks!
I have created custom pages for specific users. They can create products with attributes, prices, categories from that page. I used aimeos managers, everything works fine.
But i have an issue with media upload. This is my code.
Code: Select all
$mediaFile = $request->file('main-image');
$mediaManager = \Aimeos\MShop::create( $context, 'media' );
$mediaItem = $mediaManager->createItem();
$mediaItem->setDomain('product');
$mediaItem->setUrl($mediaFile);
$mediaItem->setPreview($mediaFile);
$mediaItem->setStatus('1');
$mediaItem->setType('default');
$mediaItem->setMimeType($mediaFile->getMimeType());
$mediaManager->saveItem($mediaItem, true);
And generate media link same as aimeos do this.
Many thanks!
Re: Upload media and attach to product from custom form
Use the media controller for that:
https://github.com/aimeos/aimeos-core/b ... /Iface.php
Here you can see how it's used by the Aimeos admin backend:
https://github.com/aimeos/ai-admin-jqad ... #L380-L384
https://github.com/aimeos/aimeos-core/b ... /Iface.php
Here you can see how it's used by the Aimeos admin backend:
https://github.com/aimeos/ai-admin-jqad ... #L380-L384
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
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Upload media and attach to product from custom form
Many thanks for your reply !
I shall try it.
Now i have another problem.
I want to get products which have stock greater than zero.
This is my code.
And this is isInStock method.
I tried everything )) Please help me if it is possible to do.
I shall try it.
Now i have another problem.
I want to get products which have stock greater than zero.
This is my code.
Code: Select all
$products = \Aimeos\Controller\Frontend::create( $context, 'product' )
->sort( $sort )
->category( $catids, 'default', $level )
->allOf( $view->param( 'f_attrid', [] ) )
->text( $view->param( 'f_search' ) )
->uses( $domains );
if( (isset($_GET['f_stock']) && $_GET['f_stock'] == '1')) {
$products = $products->isInStock();
}
$products = $products->search( $total );
Code: Select all
public function isInStock() : Iface
{
$hasfcn = $this->filter->createFunction( 'product:has', ['stock'] );
$this->conditions['is-on-sale'] = $this->filter->compare( '>=', $hasfcn, '1' );
return $this;
}
Re: Upload media and attach to product from custom form
There's no easy way to filter products by stock because there's no direct relation. Stock levels are loaded in by an async AJAX call because they are highly volatile. There have been discussed strategies using an "in-stock" attribute but you would have to implement the whole handling yourself.
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
- GagDalakyan
- Posts: 17
- Joined: 03 Dec 2020, 13:13
Re: Upload media and attach to product from custom form
I did it ) May be someone else need this. Here is example
This is product builder
This is product builder
Code: Select all
if( (isset($_GET['f_stock']) && $_GET['f_stock'] == '1')) {
$products = $products->isInStock();
}
public function isInStock() : Iface
{
$func = $this->filter->createFunction( 'product:stock', [$this->getContext()->getLocale()->getCurrencyId()] );
$this->conditions['is-in-stock'] = $this->filter->compare( '>', $func, 0 );
return $this;
}
'product:stock' => array(
'code' => 'product:stock()',
'internalcode' => 'msto."stocklevel"',
'internaldeps' => ['INNER JOIN "mshop_stock" AS msto ON ( msto."productcode" = mpro."code" )'],
'label' => 'Product stock, parameter(<currency ID>)',
'type' => 'integer',
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
'public' => true,
),
Re: Upload media and attach to product from custom form
Be aware that joining the stock table for products is painfully slow if you have more than a few hundered products!
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