Fuzzy behavior while maintaining a product model that has a price level ratio from script in Magento

I find some odd behavior when I try to save a product model from a script of this Magento Enterprise 1.8 with level 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 an exception (see below for more details). However, if I do not change anything in the model, I do not get an exception. I have a feeling that this is due to the fact that I did not update anything, so Magento does not do so 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 can successfully save the product if I install or modify level pricing information (in the expectation that I will 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 see is as follows:

: "Mage_Eav_Model_Entity_Attribute_Exception" "SQLSTATE [23000]: : 1062 " 194760-1-0-5.0000-0 " " UNQ_CATALOG_PRODUCT_TIER_PRICE "/path/to/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php:61

, , , - , .

- ? ? , .

+3
2

, , , , .

/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php , savePriceData. , , , .

if, , $priceObject, .

, priceObject value_id . catalog_product_entity_tier_price. , if

, priceObject catalog_product_entity_tier_price (entity_id, all_groups, customer_group_id, qty, value website_id). Magento catalog_product_entity_tier_price.

, script (aka ) priceObject, . , , , .

, , , . if , , , , . :

... 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);
}

, , , (, , , ). , , 100% Magento , ASAP.

, , ,

(. Enterprise Edition Magento, , , )

+1

EE 1.12, "group_price". , script

Mage:: () → setCurrentStore (Mage_Core_Model_App:: ADMIN_STORE_ID);

+5

All Articles