2014-06-21 52 views
0

我正嘗試以編程方式創建訂單。Magento:以編程方式創建訂單:可配置產品問題

有可配置的產品具有單一的基本屬性,即大小。並且一些可配置產品具有多個(多於一個)相關產品,其具有相同尺寸的值。

現在,試圖添加具有特定大小的可配置產品。但是,magento會指定首先遇到的兄弟/兒童/相關產品!因此,因SKU /兄弟姐妹下降而創建訂單。

我跟着從下面的鏈接代碼:

http://www.blog.plazathemes.com/archives/2149

http://pravams.com/2011/11/11/magento-create-order-programmatically/

有什麼辦法增加配置產品特別SKU? (類似「addProduct」方法等可接受的參數)。

回答

0

如果你有孩子的SKU,你可以這樣做:

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

如果你有大小:

$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product); 
foreach ($childProducts as $child) { 
    if ($child->getSize()==$size){ 
     //add the product to the order 
    } 
} 

,然後你在孩子圈找到的大小。

+0

感謝您的回覆,但不幸的是你提到的不是解決方案,我在找什麼。 :( 查看更多詳情:http://magento.stackexchange.com/questions/24593/magento-create-order-programatically-configurable-product-issue – Div

1

添加可配置產品以編程方式創建訂單/報價時,我面臨類似的問題。添加產品時,需要在選項陣列中設置super_attribute。該值必須包含區分相關產品(例如:顏色,大小)的屬性。因此,這將是這樣的:

$buyOptions = array(
    'qty' => 1, 
    'super_attribute' => array($attributeId => $attributeValue) //ex: array(131 => 53) 
); 
$quote->addProduct($product, new Varien_Object($buyOptions)); 

我不知道如何,如果你想通過自己的SKU選擇相關產品,但上面的代碼將工作,如果你只是想選擇從配置一個特定的相關產品。我相信它本質上是一樣的。

ps:我在這裏回答,因爲在magento stackexchange它標記爲重複(錯誤地,我認爲)。

相關問題