-
- Shili

-
Total Posts: 3
Joined: 2009-05-12
|
Hi,
I’m also trying to add programmatically configurable products (what I want to do is add them through api).
Adding, assigning with simple products, setting configurable attributes look just fine, but products are not seen at the frontend. Of course there are no errors, no warnings.
I must log in to Admin Panel, edit each configurable products, make no changes at all and save them to make them show.
I’m pretty sure I must do some mistake, but I can’t see it. I’m working on Magento ver. 1.4.0.0-rc1
The fragment of code I use:
$attributeSets = $soap->call($session_id, 'product_attribute_set.list'); $set = current($attributeSets);
$newProductData = some simple product data; $newProductData2 = some simple product data;
$newProductData3 = array( 'name' => 'name of product', 'websites' => 1, 'short_description' => 'short description', 'description' => 'description', 'price' => 12.05, 'visibility' => 4, // catalog, search 'status' => 1, // enabled 'category_ids' => array(1, 3), 'tax_class_id' => 'None' );
$data = configurable attributes data;
// Create new products $id = $soap->call($session_id, 'product.create', array('configurable', $set['set_id'], '1afafaf', $newProductData3)); $soap->call($session_id, 'product_stock.update', array('1afafaf', array('is_in_stock'=>1, 'use_config_manage_stock'=>0))); $soap->call($session_id, 'product.create', array('simple', $set['set_id'], '1afafaf-1', $newProductData)); $soap->call($session_id, 'product_stock.update', array('1afafaf-1', array('qty'=>1, 'is_in_stock'=>10, 'use_config_manage_stock'=>1))); $soap->call($session_id, 'product.create', array('simple', $set['set_id'], '1afafaf-2', $newProductData2)); $soap->call($session_id, 'product_stock.update', array('1afafaf-2', array('qty'=>1, 'is_in_stock'=>1, 'use_config_manage_stock'=>1)));
echo $soap->call($session_id, 'configurable.addSuperAttributes', array('1afafaf', $data, 'sku')); $soap->call($session_id, 'configurable.assign', array('configurable', '1afafaf', '1afafaf-1', array('position'=>0), 'sku')); $soap->call($session_id, 'configurable.assign', array('configurable', '1afafaf', '1afafaf-2', array('position'=>1), 'sku'));
And my own Api:
<?php class Companyname_Modulename_Model_Product_Api extends Mage_Catalog_Model_Product_Link_Api { public function addSuperAttributes($productId, $data = array(), $identifierType = 'sku') { $product = $this->_initProduct($productId); $res1 = $product->setConfigurableAttributesData($data); $res2 = $product->setCanSaveConfigurableAttributes(true); $product->setStatus(1); $product->setCreatedAt(strtotime('now')); try { $product->save(); } catch (Exception $e){ echo "exception:$e"; } return($res1 && $res2); } public function assign($type, $productId, $linkedProductIds, $data = array(), $identifierType = null) {
if(array_key_exists($type,$this->_typeMap)) { return parent::assign($type, $productId, $linkedProductIds, $data, $identifierType = null); } if($type=="configurable") { $product = $this->_initProduct($productId, $identifierType); if($identifierType == 'sku') { $linkedProductIds = $product->getIdBySku($linkedProductIds); $productId = $product->getIdBySku($productId); } $tmpProductIds = $product->getTypeInstance()->getUsedProductIds(); $productIds = array(); foreach($tmpProductIds as $key => $prodId) { $productIds[$prodId] = $prodId; } if(is_array($linkedProductIds)) { foreach($linkedProductIds as $prodId) { if(!key_exists($prodId,$productIds)) {$productIds[$prodId] = $prodId;} } } elseif(is_numeric($linkedProductIds)) { if(!key_exists($linkedProductIds,$productIds)) {$productIds[$linkedProductIds] = $linkedProductIds;} } else { return false; } $product->setConfigurableProductsData($productIds); try { $product->save(); } catch (Exception $e){ echo "exception:$e"; } return true; } return false; } } ?>
Sorry for my poor English, but I hope you understand what the problem is.
Thanks in advance.
|