2012-09-18 4 views
0

Magento에서 가격 업데이트를위한 샘플 og PHP 코드가 필요합니다.이 코드에 관계를 설정하는 방법을 알려주세요.Magento 등급 가격 일괄 변경

예를 들어, 가격이 500 이상인 경우 다음 번호를 입력하십시오. 아래의 코드는 모든 가격을 인상하지만, 가격이 같거나 비싸고 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"; 

?>

+0

누구나 어떤 의견이? – Eager2Learn

답변

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 
} 
+0

안녕하세요, Matt, 답변 해 주셔서 감사합니다. 또 다른 질문 - 공급 업체 XML 제품 재고 라이브 피드 (http)를 사용하여 Magento에 자동 가져 오기/업데이트 제품을 만드는 방법에 대한 조언을 나에게 줄 수 있습니까? 고맙습니다! – Eager2Learn

+0

Magento REST API 및 Linux cronjob은 괜찮습니다. – Matt