0

I have searched for a week to find the specific solution to my problem maybe one of you can help! It would be very appreciated :)

I have some products with Tier Pricing that I added through the Magento Admin backend manually and it works beautifully. I am able to update those prices programmatically and the results are amazing!

However here is my problem. For products with no current tier prices I can't add them programmatically :( I have far too many products and variations to manually go and giev each product 6 tier prices.

Here is some example code: If I call var_dump($product->getData('tier_price')) on an item with one tier.

array(1) {
  [0]=>
  array(7) {
    ["price_id"]=>
    string(3) "403"
    ["website_id"]=>
    string(1) "0"
    ["all_groups"]=>
    string(1) "0"
    ["cust_group"]=>
    string(2) "12"
    ["price"]=>
    string(7) "84.2400"
    ["price_qty"]=>
    string(6) "1.0000"
    ["website_price"]=>
    string(7) "84.2400"
  }
}

I created a variable called $standardTierPrices which is: $standardTierPrices = array(); I realize it doesn't have ["price_id"] but how can I add that if it auto increments and starts whenever created? Even with me custom setting unique ['price_id'] it still doesn't work I tested it! I also tried without all_groups and website_price, still no cigar.

>$standardTierPrices[0] = array(
    "website_id"  => "0",
    "all_groups" => "0",
    "cust_group" => "8",
    "price" => "1950.0000",
    "price_qty" => "1.0000",
    "website_price" => "1950.0000"
);

Now I call

$product->unsTierPrice()->save()->setTierPrice($standardTierPrices)->save();

If I run $product->getData('tier_prices') I can see the attribute gets added but it is not updated in the Admin panel I want the tier prices to show in the admin panel not just the attributes. Here is a specific picture of what I want and what I get. https://i.sstatic.net/NWNSc.jpg

TLDR:: I want to programmatically create this for an item -> https://i.sstatic.net/t5QaN.jpg, a tier pricing in the Admin Panel

From a product that starts with no tier pricing.

2 Answers 2

1

I would try removing all_groups and website_price and using integers or floats unless you need strings for the prices. Try this:

$adminId = Mage::app()->getWebsite(false)->getDefaultGroup()->getDefaultStoreId();
Mage::getModel('catalog/product')->load(123)
    ->setTierPrice(array(
        array(
            'cust_group' => 8,
            'price' => 1950,
            'price_qty' => 1,
            'website_id' => $adminId
        ),
        array(
            'cust_group' => 9,
            'price' => 1900,
            'price_qty' => 1,
            'website_id' => $adminId
        ),
    ))
    ->save();
3
  • Thanks for the quick response but still not working :( I took out all_groups and website_price it saves to the product's attribute ['tier_price'] still but doesn't show up in the Admin Magento section. Commented May 26, 2016 at 0:46
  • Can you provide more code samples, and/or test with with the smallest code possible to rule out other issues? Also, which version of Magento?
    – Tyler V.
    Commented May 26, 2016 at 1:31
  • Sure Tyler! Magento ver. 1.7.0.2 I'll update the question to have simpler examples :) Commented May 26, 2016 at 20:54
1

Awesome so I got it working! If any of you have questions leave them in the comments and I'll do my best to help you out too!

So I had to add a special variable

$standardTierPrices = array(); $adminId = Mage::app()->getWebsite(false)->getDefaultGroup()->getDefaultStoreId();

$standardTierPrices[0] = array( "website_id" => "$adminId", "cust_group" => "8", "price" => "1950.0000", "price_qty" => "1.0000", );

By using the admin ID it matched it and correctly added it to the backend and the Admin Panel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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