Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $product = Mage::getModel('catalog/product');
- $product->setTypeId('configurable');
- //$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
- $product->setWebsiteIds(array(1));
- $product->getTypeInstance()->setUsedProductAttributeIds(array(132));
- $configurableAttributesData = $product->getTypeInstance()->getConfigurableAttributesAsArray();
- $product->setCanSaveConfigurableAttributes(true);
- $product->setConfigurableAttributesData($configurableAttributesData);
- $product->setName($name);
- $product->setDescription($description);
- $product->setShortDescription($shortdescription);
- $product->setSku($sku);
- $product->setWeight($weight);
- $product->setStatus(1); // enabled
- $product->setVisibility(4); // catalog, search
- //$product->setNewsFromDate(date('d/m/Y'));
- $product->setNewsFromDate(date('m/d/Y', strtotime(date("Y/m/d"). ' - 1 days')));
- $product->setNewsToDate(date('m/d/Y', strtotime(date("Y/m/d"). ' + 2 days')));
- $product->setPrice($price);
- $product->setSpecialPrice($sprice);
- $product->setTaxClassId(2); // taxable goods
- $product->setAttributeSetId(4); // need to look this up
- //CATEGORYS
- $product->setCategoryIds(array(if_exists_2_main($catparent,$catson),getTopCatId($catparent)));
- //IMG
- $importDir = Mage::getBaseDir('media') . DS . 'import/';
- for ($i=0; $i < sizeof($image); $i++) {
- try {
- if($image[$i] == ""){
- break;
- }
- if(!file_exists($importDir.$sku.$i.'.jpg')){
- //echo "NOT EXIST<br>";
- copy($image[$i], $importDir.$sku.$i.'.jpg');
- }
- /*else{
- echo "EXIST<br>";
- }*/
- if($i == 0){
- $product->addImageToMediaGallery($importDir.$sku.$i.'.jpg', array('image', 'small_image', 'thumbnail'), false, false);
- }
- else{
- $product->addImageToMediaGallery($importDir.$sku.$i.'.jpg', array('', '', ''), false, false);
- }
- } catch (Exception $e) {
- }
- }
- $productData = array();
- foreach ($variable as $value) {
- $productData[$value[0]] = array('0' => array('attribute_id' => '132', 'label' => $value[1],'value_index' => getOptionId("sizematters",$value[1]), 'is_percent' => 0, 'pricing_value' => ''));
- }
- $product->setConfigurableProductsData($productData);
- $product->save();
- // Check if there is a stock item object
- $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
- $stockItemData = $stockItem->getData();
- if (empty($stockItemData)) {
- // Create the initial stock item object
- $stockItem->setData('manage_stock',1);
- $stockItem->setData('is_in_stock',1);
- $stockItem->setData('use_config_manage_stock', 0);
- $stockItem->setData('stock_id',1);
- $stockItem->setData('product_id',$product->getId());
- $stockItem->save();
- // Init the object again after it has been saved so we get the full object
- $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement