Magento Cash Price Changes

What I'm trying to do is change the prices of products in a certain category. We get recommended retail prices from our supplier, but sometimes they do not work for us. Therefore, we need to take the cost of the product and, for example, add 20% to the product, so .. just enough cost = cost + 0.2 * cost. Now I need to do this on all products in the selected category, so here's what I still have ...

$category = Mage::getModel('catalog/category')->load(189); 

// load products from category id '189'
$products   = Mage::getModel('catalog/product')
                ->getCollection()  
                ->addCategoryFilter($category)  
                ->addAttributeToSelect('id'); 

foreach($products as $product) { 
    // get the current cost of the product
    $cost = $db->fetchRow("SELECT value FROM `m_catalog_product_entity_decimal` WHERE entity_id='" . $product->getId() . "' AND attribute_id='68'");
    $cost = $cost['value']; 
    $newCost = $cost + $cost*$percentage; 

    // update the product with a new cost
    $db->query("UPDATE `m_catalog_product_entity_decimal` SET value='$newCost' WHERE entity_id='" . $product->getId() . "' AND attribute_id='64'"); 
}

SQL, php- magento ( Magento 1.4 ). "id" , . , SQL- , . 10 , , 500 .

SQL- foreach . - 68, - 64. .


Magento EAV . , , "" "", m_catalog_product_entity_decimal

,

value_id    entity_type_id  attribute_id    store_id    entity_id   value
6401             4              64             0            2184      399.9500

_id - , entity_type_id 4 , . attribute_id . 64 _id "". Store_id . Entity_id - , - .

+5
4

, B00MER , . , SQL. 1,2 , - :

update catalog_product_entity_decimal
  set value = value*1.2
  where attribute_id = 75 and
        entity_id IN (select product_id from catalog_category_product
                    where category_id = X);

, , , . , X , , m_, ( , ).

, !

,

+10

Magento ORM ( , , ) . 1.4 CE, "Magento" . Unigry Data RapidFlow, , , /,

+2

magmi, SQL. .

+1

magento :

$product = Mage::getModel('catalog/product')->load($id);
$product->setData('price',$value);
$product->save();
0

All Articles