Magento-level product prices are removed when updating product images

I created a script to update software products, but my scripts remove all tier_prices on $product->save();

Here is my bilder script update:

foreach ($productCollection as $product) {

    $formatted_sku = $product->getSku();
    $config = $product->getMediaConfig();



    // JPG files verification
    $jpg_file = $images_folder.$formatted_sku.".".$extension[0];
    if (file_exists($jpg_file) ) {
        $fileurl = $config->getMediaUrl($jpg_file);
        $product->addImageToMediaGallery($jpg_file, $visibility, false, false);
        $product->save();

    }
}

How can I avoid updating my tier_prices?

Many thanks.

+1
source share
4 answers

For those of you who are still facing this problem, there is a simple solution to try. It seems that tierprice data is not read by default for getModel for the product. To fix this, simply call the product's getTierPrice method to load it.

$tp=$product->getTierPrice();

You do not need to do anything, just download it. Then, when you save the product, tiered pricing data is saved.

+3
source

. , , , . "" tierprice:

$tierPrices = array(
              'website_id'  => 0,
              'cust_group'  => 2,
              'price_qty'   => 3,
              'price'       => 10
             );

( , [])

( ), :

$product->setTierPrice($tierPrices);

, , :

$product->save();

. , !

+1

$productCollection? , (tier_prices), save() . addAttributeToSelect()

0

, . false - , /.

$product->setTierPrice(false);

, , , , . , , GregC, , , , , .

OP.

foreach ($productCollection as $product) {
    $formatted_sku = $product->getSku();
    $config = $product->getMediaConfig();

    // JPG files verification
    $jpg_file = $images_folder.$formatted_sku.".".$extension[0];
    if (file_exists($jpg_file) ) {
        $fileurl = $config->getMediaUrl($jpg_file);
        $product->addImageToMediaGallery($jpg_file, $visibility, false, false);
        $product->setTierPrice(false);  // set tier price to false to prevent it from being overwritten
        $product->save();
    }
}

Magento EE 1.14.12.0

0

All Articles