0

ここに少し助けが必要です.Magentoで価格を更新するためのサンプルog phpコードです.誰かがこのコードに関係を入れる方法のヒントを教えてください.

たとえば、これが必要です: 価格が >=500 の場合、層 = 1.8 以下のコードはすべての価格を引き上げますが、500 USD と同等または高価な製品の価格のみを引き上げる必要があります。

<?php

$server     = "localhost";
$database   = "";
$user       = "";
$password   = "";

$myConn = mysql_connect( $server, $user, $password ); 
$select = mysql_select_db( $database, $myConn );

$query = "SELECT
            value_id, value
        FROM
            catalog_product_entity_decimal
        ORDER BY
            value_id
        ASC";

$result = mysql_query($query) or die(mysql_error()); 

// 1.04 = 4% (duh) ovdje idu postavke marze
$tier   = 1.04;
$i      = 0;

while( $row = mysql_fetch_array($result) )
{
    if( $row["value"] != NULL )
    {
        $value          = 0;
        $value          = $row["value"];

        $value          = round( $value * $tier );


        $updQuery = "UPDATE
                        catalog_product_entity_decimal
                    SET
                        value = ".$value."
                    WHERE
                        value_id = ".$row["value_id"];

        $updResult = mysql_query($updQuery) or die(mysql_error());

        $i++;

        print "value_id: ".$row["value_id"]." | ";
        print "old price: ".$row["value"]." -> ";
        print "new price: ".$value."<br/>";
    }

}

print "<br/><br/><hr><br/><b>".$i."</b> records updated.<br/><br/>Now go to system -> index management -> and reindex everything";

?>

4

1 に答える 1

1
The Magento way
$tier = 1.04;
$products = Mage::getModel('catalog/product')->getCollection
    ->addAttributeToFilter('price' , array( 'gteq' => 500))
    ->load();
foreach($products as $product){
    $product->setPrice($product->getPrice() * $tier);
    $product-save();
}

sql direct query
//first get price attribute id
$sql = 'select attribute_id from eav_attribute where attribute_code= "price"';
$attribute_id = mysql_query($sql);

//get entity id  which price >=500
$sql = "select eneity_id from catalog_product_entity_decimal d where attribute_id = {$attribute_id[0]} and d.value >= 500";
while($row = mysql_fetch_array($result)){
    // do something
}
于 2012-09-29T10:51:33.863 に答える