Show cheapest variant price as selection product's price
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!
Show cheapest variant price as selection product's price
Hi.
I would like to change the logic behind the price shown for a select product.
On this page, the price of the Demo selection article must get changed.
The price must be the cheapest price, among all the variant products. For instance, by opening the product's page you can see there are two sub-products. One is colored blue, and another is beige. If the blue one's price is 100$ and the beige's price is 120$, on the home page, lists page, suggested product list, etc. 100$ must be shown as the Demo selection article's price.
I considered adding a new method to the product's controller, but how can I call a controller in?
PS-
In config I have set:
There are multiple sites in my shop, so each sub-product may have multiple sellers. Some of the prices are useless if the stock item for the corresponding seller is 0.
I have to filter through the price items based on the stock level of the seller, and also remove those sellers that are not enabled (since I use the 'ai-sites' extension).
So the question is how to call a method for getting the cheapest valid price in 'common/partials/products-standard'
I would like to change the logic behind the price shown for a select product.
On this page, the price of the Demo selection article must get changed.
The price must be the cheapest price, among all the variant products. For instance, by opening the product's page you can see there are two sub-products. One is colored blue, and another is beige. If the blue one's price is 100$ and the beige's price is 120$, on the home page, lists page, suggested product list, etc. 100$ must be shown as the Demo selection article's price.
I considered adding a new method to the product's controller, but how can I call a controller in
Code: Select all
common/partials/products-standard
PS-
In config I have set:
Code: Select all
mshop/common/manager/maxdepth = 3
I have to filter through the price items based on the stock level of the seller, and also remove those sellers that are not enabled (since I use the 'ai-sites' extension).
So the question is how to call a method for getting the cheapest valid price in 'common/partials/products-standard'
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Show cheapest variant price as selection product's price
If you've passed
as domains that are fetched along with the products shown in the list view, you can do the following to get the cheapest price of all sub-products for one product item:
Please keep in mind that this isn't the most performant way because you have to load a lot of data and that sorting by price won't yield the correct order. If you are able to add the cheapest price to the selection product when saving the variant articles (e.g. in the admin backend), this will be much faster and requires less data loaded from the database.
Code: Select all
['product', 'price', 'text', 'stock', ...]
Code: Select all
$prices = $product->getRefItems( 'product', 'default', 'default' ) // get all variant articles
->filter( function( $item, $id ) { // filter products with stock
return $item->getStockItems()->getStockLevel()
->filter( function( $stock) { // filter stock levels > 0 and unlimited
return $stock=== null || $stock > 0;
} );
} )->getRefItems( 'price', 'default', 'default' ); // get all variant price items
$price = \Aimeos\MShop::create( $context, 'price' )->getLowestPrice( $prices, 1 );
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: Show cheapest variant price as selection product's price
Hi
The solution mentioned here works fine for me.
However, I have an issue in getting price items on the home page.
Is there a way to change the domains here somehow, so that promoted products are returned with their referenced subProducts? And subProducts
must have their prices with them as reference items.
The solution mentioned here works fine for me.
However, I have an issue in getting price items on the home page.
Is there a way to change the domains here somehow, so that promoted products are returned with their referenced subProducts? And subProducts
must have their prices with them as reference items.
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Show cheapest variant price as selection product's price
You've already found the configuration options for changing the used domains:
https://github.com/aimeos/ai-client-htm ... #L439-L440
https://github.com/aimeos/ai-client-htm ... #L439-L440
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: Show cheapest variant price as selection product's price
That's right.
I want to know how to change the Value of config so that all promoted products are retrieved with their stock, price, and subproducts items.
maybe something like:
Right now the promotion products only have text and media as their reference items.
I want to know how to change the Value of config so that all promoted products are retrieved with their stock, price, and subproducts items.
maybe something like:
Code: Select all
['media', 'media/property', 'price', 'text', 'product' => ['promotion' => ['stock', 'product', ...]]
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Show cheapest variant price as selection product's price
Use:
Code: Select all
['media', 'media/property', 'price', 'text', 'product' => ['promotion', 'default'], 'stock']
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: Show cheapest variant price as selection product's price
Stock items are not added to list items by adding `stock` to this array. Interesting is, that by deleting `media` from this array the media items won't be fetched. I even tested this with a fresh installation of the Aimeos project.
Are there any other files that I should check?
Are there any other files that I should check?
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Show cheapest variant price as selection product's price
Stock items are available by using:
They are not linked via the mshop_product_list table
Code: Select all
$product->getStockItems()
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