Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:42:06+00:00 2026-06-02T03:42:06+00:00

I am finding some odd behavior when I try to save a product model

  • 0

I am finding some odd behavior when I try to save a product model from a script it Magento Enterprise 1.8 that has tier pricing.

Take this code for example:

// This product has a tier price
$product = Mage::getModel('catalog/product')->load(194760);
$product->setName('Changed Product Title');
$product->save();

When saving a get an exception (detailed below). However if I change nothing in the model, I do not get the exception. I have a feeling that this is due to the fact that I did not update anything so Magento does not do as much work.

// Same product, but I changed nothing and it works 
$product = Mage::getModel('catalog/product')->load(194760);
$product->save();

The odd part is that I am able to save the product successfully if I am setting or modifying tier price information (pending I do not create anything that is duplicated)

// This works pending the tier price does not already exist
$mud_array = array();
$mud_array[] = array(
    'website_id' => 0,
    'cust_group' => 32000,
    'price_qty' => 5,
    'price' => 6
);
$product = Mage::getModel('catalog/product')->load(194760);
$product->setTierPrice($mud_array);
$product->save();

The exception that I am seeing is as follows:

Fatal error: Uncaught exception ‘Mage_Eav_Model_Entity_Attribute_Exception’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘194760-1-0-5.0000-0’ for key ‘UNQ_CATALOG_PRODUCT_TIER_PRICE” in /path/to/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php:61

So it appears that when a tier price exists in a product, and you try to change anything inside the model, it will attempt to reinsert all the tier price information.

Has anyone seen this before? Is there a way to work around this? Thanks for any help you can provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:42:07+00:00Added an answer on June 2, 2026 at 3:42 am

    Ok so I created a fix for this that seems to work.

    In /app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php there is a function called savePriceData. From what I can gather this function is responsible for determining if we need to update or insert a tier price.

    There is an if block that makes this decision to update or insert based on the information coming from the $priceObject that is passed to the function.

    If you are updating a tier price from the admin panel, priceObject has two values value_id and value. These fields both point to columns in the catalog_product_entity_tier_price table. This is what happens in the first part of the if block

    If you are creating a new tier price from the admin panel, priceObject has all the columns from the catalog_product_entity_tier_price table (entity_id, all_groups, customer_group_id, qty, value, and website_id). Magento then takes this information and inserts it into the catalog_product_entity_tier_price table.

    The actual problem was that when you save a product from a script (aka outside the admin panel) you ALWAYS get a priceObject that contains all the information for an insert. So it will always try to do the insert into the table which if it already exists causes an integrity constraint violation.

    So the fix I put together for this was really quite simple. In the second part of the if block, I am doing a check to see if the tier price already is in the table and if it is, I simply do not do the insert. Here is the code:

    ... first part of if statement
    // somehow we need to have this not happen if it already exists
    $reader = $this->_getReadAdapter();
    $sql = "SELECT * FROM catalog_product_entity_tier_price WHERE ";
    foreach($data as $index => $value) {
    $sql .= $index . ' = ' . $value . ' AND ';
    }
    $sql = substr($sql, 0, -4);
    $search = $reader->fetchAll($sql);
    if(count($search) > 0) {
    // It already exists, don't do anything
    } else {
    $adapter->insert($this->getMainTable(), $data);
    }
    

    Obviously, you really should make sure that you copy this file to local before you make this change (or probably better yet, rewrite it in a module). This probably is not the most 100% correct “Magento way” to do this, but I really needed to get a solution for this ASAP.

    I am open to better solutions than this, but I wanted to share what I found

    (Note: As I am on the Enterprise Edition of Magento, I did not want to share anymore of the source than necessary since it could be a violation of our license agreement)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Again I'm moving from Xcode 3 to 4 and finding that some things are
I've been playing with jQuery in an ASP.NET project and am finding some odd
I'm finding some problems with a query that returns the sum of a field
I am manually converting code from Java (1.6) to C# and finding some difficulty
I am finding some unexpected behavior when using a projection in a LINQ to
I recently created my first Heroku application and I'm finding some strange behavior: When
I keep finding some JavaScript that looks like the example below. Can someone explain
I've moved from iOS applications development to android so I'm facing some problems finding
I am trying to save some data on the server but finding some encoding
I am using matplotlib and I'm finding some problems when trying to plot large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.