2014-01-27 3 views
1

코드별로 제품 등급 가격을 추가하는 데 문제가 있습니다. 필자는 계층 적 가격을 추가하는 데 사용할 수있는 magento API가 있다는 조사를 수행했습니다. 그러나 magento를 사용자 정의하고 "생산 시간"인 계층 가격에 새로운 필드를 추가 했으므로 API를 통해 계층 가격을 추가하는 방법을 모르겠습니다. 여기 Magento는 프로그래밍 방식으로하지만 사용자 정의 필드로 가격을 책정합니다.

샘플 코드

$proxy = new SoapClient(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/api/soap/?wsdl'); 
$sessionId = $proxy->login('API user','API Key'); 
$tierPrices[] = array(
    'website'   => 'all', 
    'customer_group_id' => 'all', 
    'production_time => $data[2], 
    'qty'    => $data[3], 
    'price'    => $data[4] 
); 
try { 
     $proxy->call($sessionId, 'product_tier_price.update', array($sku, $tierPrices)); 
    } catch (Exception $e) { 
     $e->getMessage() . "\n"; 
} 

나는 오류가 발생합니다 "잘못된 계층 가격"라고합니다.

왜 그런가? 또는 다른 방법으로 계층 가격을 추가 할 수 있습니까?

감사합니다.

답변

-1

모든 기능은 당신이 표준 젠토 스크립트를 사용할 수있는 API보다 더 나은, 당신은 단지 젠토 폴더에 삽입 될해야합니다

require("../../app/Mage.php"); 
Mage::init(); 

// Set an Admin Session 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
Mage::getSingleton('core/session', array('name' => 'adminhtml')); 
$userModel = Mage::getModel('admin/user'); 
$userModel->setUserId(1); 
$session = Mage::getSingleton('admin/session'); 
$session->setUser($userModel); 
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); 


foreach ($youritemlist as $item) { 


    $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item); 

    if(is_object($product)) {    


       $product->setTierPrice($yourprice); 
       echo "..(set).."; 


         $product->save();       

         echo "..saved\n";          

     }; // end testing of product exist    


}; // enf foreach 
+0

$ yourprice를 올바르게 설정하는 방법을 보여 주면 도움이 될 것입니다. –

1

내가 모델을로드하는 가장 쉬운 것을 발견했다 그 API는 계층화 가격에 사용되므로 데이터의 유효성을 검사하여 도움을받을 수 있습니다.

$tierPrices = array(); 

$tierPrices[] = array(
    'customer_group_id' => 1,  // or 'all' or whatever your customer group ID is 
    'qty'    => 1,  // Must be greater than 0 
    'price'    => 5.99, // Use an int here, don't currency format 
    'website_id'  => 0  // or whatever website ID you need to set this to 
); 

// Set more tiered prices here if you'd like... 

$tierPriceModel = Mage::getModel('catalog/product_attribute_tierprice_api'); 

// Assume 12345 is your product ID 
$tierPriceModel->update(12345, $tierPrices); 
0

그 계층의 가격을 고려하여 업데이트되지 않은 이유를 궁금해 나 같은 website_id 변경 @Tyler V. 코드 또는 API 코드에서 실수가 있기 때문입니다 FO.

이 올바른 새로운 계층의 가격을 포맷하는 방법입니다 : 당신이 계층의 가격 배열에 웹 사이트를 지정 website_id

$tierPrices[] = array(
    'customer_group_id' => 'all',  
    'qty'    => 1,  
    'price'    => 5.99,  
    'website'  => 0   
); 

이 더 이상하지만 웹 사이트!