3

when I sort by price product order in Asc or dec. In product listing shows like, First product price is 40, second product price is 50 and the third product price is 40.

If I opened and save those 50 price product in admin backend that product, it's working fine.

All product have customizable options. When I run the following script it's working fine. But this script will delete those customizable options.

<?php

use Magento\Framework\App\Bootstrap;

include 'app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');


$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

$productCollection->load();

foreach($productCollection  as $product)
{
 $product->save();

}

echo "saved";

Find any possible way to fix this issue. advance thanks

1

Try to load the product options with your collection. The product collection does not load options by default since they are not used in product lists. Maybe that have impact on what you are doing in your code.

$productCollection->addOptionsToResult()->load();

  • It's not deleted the customizable options and product listing is working fine. But Customizable option not shown in frontend product detail page. But if open and save those products again in the admin panel, it's working fine – MSA Feb 15 at 11:43
  • Sorry but I can't follow: In your question you have a product listing with sorting prices and some script which deletes your custom options. Now you tell me, the script is not deleting custom options but you are not seeing custom option changes in product view. If your question is related to sorting its most likely something with the search index, but I don't see the relation between price sorting in product lists and custom options in product detail page :-) – HelgeB Feb 15 at 12:10
  • While executing my initial script, it saved the product data and deletes its custom options data. After included your suggestion in the script, now the product data and its custom options data are saved properly. But we face the issue, In product detail page like the products details are showing without the selection options of custom options. Then we need to go backend and requires to save manually of that product without changing anything for showing the selection options of custom options in frontend product detail page. – MSA Feb 15 at 12:38
  • Ok, thanks for the details, now I see a little clearer :-) You may have a cache issue there. Try to flush the cache after running your script. – HelgeB Feb 15 at 12:46
  • thanks for the understanding. Even we tried to clear the cache and also did the reindex. But it does not help us. – MSA Feb 15 at 12:48
1

Try this,

<?php                                                                       
use Magento\Framework\App\Bootstrap;                                    
include 'app/bootstrap.php';                                         
$bootstrap = Bootstrap::create(BP, $_SERVER);                    
$objectManager = $bootstrap->getObjectManager();                         
$state = $objectManager->get('Magento\Framework\App\State');            
$state->setAreaCode('frontend');                             
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); 
$productCollection->addAttributeToSelect('*');              
$productCollection->addAttributeToSort('price', 'ASC');  

foreach($productCollection  as $product){                      
    $product = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);                            
    $product->save();                                                 
}                      
  echo "saved";

Hope this helps, peace :)

  • Thanks for the reply. I just want to save product script without deleted those products customizable options – MSA Feb 15 at 8:09
  • updated try this. – Prathap Gunasekaran Feb 15 at 8:51
  • Your updated script is also deleted customizable options of all products. – MSA Feb 15 at 10:05
  • Give it try again – Prathap Gunasekaran Feb 15 at 10:08
  • Now it's not deleted the cutomizable options. But products sorting by price is not working properly bro – MSA Feb 15 at 11:14
0

We are having the sort by price issue on Magento 2.3.0 Ex: A product price 100$ customizable option price starts with 50, B product price 110$ customizable option price starts with 20 and C product price 120$ customizable option price starts with 20.

We are expecting sort by price is product A, product B, and product C but its showings like product B, product C, and product A.

Because results are showing with the lowest customizable option price like product B 130$, product C 140$, and product A 150$.

So we nee the price displays with the lowest customizable option. Or Sorting needs to show without calculating the customizable option price.

  • Kindly post as questions – MSA Apr 24 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.