0

We have more then 50000 products in our website and i want update tier price for existing website. I have added code for update tier price for 4 customer groups. and it is working for 500 to 600 products. but when i want all products tier price then it is showing 500 error. please give me solution or how to use callback function in magento2 so that i can update products tier price I have used code like and it is working 500 to 600 products limit

 use \Magento\Catalog\Api\ProductTierPriceManagementInterface;
 include('app/bootstrap.php');
 $bootstrap = Bootstrap::create(BP, $_SERVER);
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $state = $objectManager->get('Magento\Framework\App\State');
 $state->setAreaCode('frontend');
 $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
 $productcollection = $productCollection->addAttributeToSelect('*')->setOrder('entity_id','ASC')->setPageSize(800)->load();;
 $i=1;  
 $tierPrice= array();             
 foreach ($productcollection as $product) 
 { 
         $p_id = $product->getId();
         $p_price = $product->getPrice();
         if($p_price >0)
         { 
             $newPrice1=($p_price /2.5)*2;
             $newPrice2=($p_price /2.5)*1.8; 
             $newPrice3=($p_price /2.5)*1.6;
             $newPrice4=($p_price /2.5)*1.4;
             $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
             $productObj = $productRepository->getById($product->getId());
             $tierPrice[0] = array('website_id' => 0,'cust_group' => 5, 'price_qty' => 1 , 'price' => $newPrice1);
             $tierPrice[1] = array('website_id' => 0,'cust_group' => 6, 'price_qty' => 1 , 'price' => $newPrice2);
             $tierPrice[2] = array('website_id' => 0,'cust_group' => 7, 'price_qty' => 1 , 'price' => $newPrice3);
             $tierPrice[3] = array('website_id' => 0,'cust_group' => 8, 'price_qty' => 1 , 'price' => $newPrice4);
             // $productObj->setPrice(103.59);
             $productObj->setTierPrice($tierPrice);
             $productObj->save();   
             echo "Price Updated for Product Id : " .  $p_id."</br>";
             echo"Product count number " . $i."<br/>";
         }
   $i++;
          
 } ```
0

We have a site with 300k products, and I tried quite a few extensions for loading our data. The best one I've found is from Wyomind - Mass Product Import and Export ($210).

https://www.wyomind.com/mass-product-update-import-magento.html

It handles every loading scenario I've needed, and I just checked - it does tiered pricing too. One feature it has is to upload a large file with all of your data, but only import specified rows. I was able to use this to load 20k rows at a time so that I didn't run out of memory (2GB limit from our host).

My apologies if you are not looking for a paid extension. For us the flexibility and ease of use was well worth it.

1
  • Thank you for your reply. sorry i am not looking paid extension. i want update tier price using price based on customer group and set different2 price for customer group and using root file like mywebsite.com/update_price.php and this file run every day one time. – user3811650 Sep 9 '20 at 14:16

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.