2016-07-23 84 views
0

我創建了一個模塊發送產品到另一臺服務器具有json結構這樣獲取產品變型

{ 
name: "Black Nolita Cami", 
code: "877", 
sku: "wbk002c", 
price: "150.0000", 
sale_price: "wbk002c", 
discount: "", 
quantity: "0.0000", 
weight: null, 
url: "black-nolita-cami.html"} 

,但我有我已經把所有不同產品在那裏如何做我這另一場變種?

回答

1

這可能讓你在正確的方向開始......

$productSku = "ABCDE"; 
$product = Mage::getModel('catalog/product'); 
$productId = $product->getIdBySku($productSku); 
$product->load($productId); 

/** 
* In Magento Models or database schema level, the product's Custom Options are 
* executed & maintained as only "options". So, when checking whether any product has 
* Custom Options or not, we should check by using this method "hasOptions()" only. 
*/ 
if($product->hasOptions()) { 
    echo '<pre>'; 

    foreach ($product->getOptions() as $o) { 
     $optionType = $o->getType(); 
     echo 'Type = '.$optionType; 

     if ($optionType == 'drop_down') { 
      $values = $o->getValues(); 

      foreach ($values as $k => $v) { 
       print_r($v); 
      } 
     } 
     else { 
      print_r($o); 
     } 
    } 

    echo '</pre>'; 
}