Exemple #1
0
 public function testGetPriceModel()
 {
     $this->_model->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE);
     $type = $this->_model->getPriceModel();
     $this->assertInstanceOf('Mage_Bundle_Model_Product_Price', $type);
     $this->assertSame($type, $this->_model->getPriceModel());
 }
Exemple #2
0
 public function testGetPriceModel()
 {
     $default = $this->_model->getPriceModel();
     $this->assertInstanceOf('Mage_Catalog_Model_Product_Type_Price', $default);
     $this->assertSame($default, $this->_model->getPriceModel());
     $this->_model->setTypeId('configurable');
     $type = $this->_model->getPriceModel();
     $this->assertInstanceOf('Mage_Catalog_Model_Product_Type_Configurable_Price', $type);
     $this->assertSame($type, $this->_model->getPriceModel());
 }
Exemple #3
0
 /**
  * @covers Mage_Catalog_Model_Product::isConfigurable
  * @covers Mage_Catalog_Model_Product::isSuperConfig
  * @covers Mage_Catalog_Model_Product::isSuper
  */
 public function testIsConfigurable()
 {
     $this->assertFalse($this->_model->isConfigurable());
     $this->assertFalse($this->_model->isSuperConfig());
     $this->assertFalse($this->_model->isSuper());
     $this->_model->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE);
     $this->assertTrue($this->_model->isConfigurable());
     $this->assertTrue($this->_model->isSuperConfig());
     $this->assertTrue($this->_model->isSuper());
 }
Exemple #4
0
 public function testValidate()
 {
     $this->_model->setTypeId('simple')->setAttributeSetId(4)->setName('Simple Product')->setSku(uniqid('', true) . uniqid('', true) . uniqid('', true))->setPrice(10)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setCollectExceptionMessages(true);
     $validationResult = $this->_model->validate();
     $this->assertEquals('SKU length should be 64 characters maximum.', $validationResult['sku']);
     unset($validationResult['sku']);
     foreach ($validationResult as $error) {
         $this->assertTrue($error);
     }
 }
Exemple #5
0
 public function testInitProductLayout()
 {
     $uniqid = uniqid();
     $product = new Mage_Catalog_Model_Product();
     $product->setTypeId(Mage_Catalog_Model_Product_Type::DEFAULT_TYPE)->setId(99)->setUrlKey($uniqid);
     $this->_helper->initProductLayout($product, $this->_controller);
     $rootBlock = $this->_controller->getLayout()->getBlock('root');
     $this->assertInstanceOf('Mage_Page_Block_Html', $rootBlock);
     $this->assertContains("product-{$uniqid}", $rootBlock->getBodyClass());
     $handles = $this->_controller->getLayout()->getUpdate()->getHandles();
     $this->arrayHasKey('PRODUCT_99', $handles);
     $this->arrayHasKey('PRODUCT_TYPE_simple', $handles);
 }
Exemple #6
0
 public function testGetOptionValuesCaching()
 {
     $block = Mage::app()->getLayout()->createBlock('Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option');
     $productWithOptions = new Mage_Catalog_Model_Product();
     $productWithOptions->setTypeId('simple')->setId(1)->setAttributeSetId(4)->setWebsiteIds(array(1))->setName('Simple Product With Custom Options')->setSku('simple')->setPrice(10)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
     $product = clone $productWithOptions;
     $option = new Mage_Catalog_Model_Product_Option(array('id' => 1, 'title' => 'some_title'));
     $productWithOptions->addOption($option);
     $block->setProduct($productWithOptions);
     $this->assertNotEmpty($block->getOptionValues());
     $block->setProduct($product);
     $this->assertNotEmpty($block->getOptionValues());
     $block->setIgnoreCaching(true);
     $this->assertEmpty($block->getOptionValues());
 }
 public function saveAnimalAction()
 {
     $request = $this->getRequest()->getPost();
     $leiloeiro = Mage::getModel('leilao/leiloeiro')->getCurrentLeiloeiroSession();
     $leiloeiro_product = Mage::getModel('leilao/product');
     $product = new Mage_Catalog_Model_Product();
     $product->setAttributeSetId(4);
     // #4 is for default
     $product->setTypeId('simple');
     $product->setName($request['name']);
     $product->setDescription($request['description']);
     $product->setShortDescription('Short description here');
     $product->setSku(time());
     $product->setWeight(1.0);
     $product->setStatus(1);
     $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
     //4
     $product->setPrice($request['price']);
     // # Set some price
     $product->setTaxClassId(0);
     // # default tax class
     $product->setStockData(array('is_in_stock' => 1, 'qty' => 1));
     //$product->setCategoryIds(array(27)); // # some cat id's,
     $product->setWebsiteIDs(array(1));
     // # Website id, 1 is default
     //Default Magento attribute
     $product->setCreatedAt(strtotime('now'));
     //print_r($product);
     try {
         $product->save();
         $leiloeiro_product->setData('id_leiloeiro', $leiloeiro->getData('entity_id'));
         $leiloeiro_product->setData('id_product', $product->getId());
         $leiloeiro_product->save();
         echo "Product Created";
     } catch (Exception $ex) {
         //Handle the error
         echo "Product Creation Failed";
     }
 }
Exemple #8
0
 /**
  * @param array $productData
  * @param Mage_Catalog_Model_Product $product
  * @return mixed
  */
 public function processData(array &$productData, $product)
 {
     $attributeSetId = $productData['attribute_set_id'];
     $sku = $productData['sku'];
     $product->setAttributeSetId($attributeSetId);
     if (!$product->getId()) {
         if (empty($productData['type_id'])) {
             $this->_throwException('Product type is not specified', 'product_type_not_passed');
         }
         $type = $productData['type_id'];
         $this->_checkProductTypeExists($type);
         $product->setTypeId($type)->setSku($sku);
         if (!isset($productData['stock_data']) || !is_array($productData['stock_data'])) {
             //Set default stock_data if not exist in product data
             $product->setStockData(array('use_config_manage_stock' => 0));
         }
     }
     $this->_prepareDataForSave($product, $productData);
     try {
         if (is_array($errors = $product->validate())) {
             $strErrors = array();
             foreach ($errors as $code => $error) {
                 if ($error === true) {
                     $error = Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code);
                 }
                 $strErrors[] = $error;
             }
             $this->_throwException(implode("\n", $strErrors), 'invalid_product_data');
         }
         $product->save();
     } catch (Mage_Core_Exception $e) {
         $this->_throwException($e->getMessage(), 'error_saving_product');
     }
     $productData['product_id'] = $product->getId();
     return $product->getId();
 }
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @subpackage  performance_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$installer = new Mage_Catalog_Model_Resource_Setup('catalog_setup');
/**
 * After installation system has two categories: root one with ID:1 and Default category with ID:2
 */
$category = new Mage_Catalog_Model_Category();
$category->setId(3)->setName('Category 1')->setParentId(2)->setPath('1/2/3')->setLevel(2)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->setPosition(1)->save();
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))->setStoreId(1)->setWebsiteIds(array(1))->setName('Simple Product')->setDescription('Description')->setShortDescription('Desc')->setSku('simple')->setPrice(10)->setWeight(18)->setCategoryIds(array(2, 3))->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setTaxClassId(0)->save();
$stockItem = new Mage_CatalogInventory_Model_Stock_Item();
$stockItem->setProductId($product->getId())->setTypeId($product->getTypeId())->setStockId(Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID)->setIsInStock(1)->setQty(10000)->setUseConfigMinQty(1)->setUseConfigBackorders(1)->setUseConfigMinSaleQty(1)->setUseConfigMaxSaleQty(1)->setUseConfigNotifyStockQty(1)->setUseConfigManageStock(1)->setUseConfigQtyIncrements(1)->setUseConfigEnableQtyInc(1)->save();
 /**
  * extract the first element of a dom node list make sure it is lower case
  * if there's no item in the DOMNodeList return the default simple product type constant value
  *
  * @param DOMNodeList $nodes
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function extractProductTypeValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     $value = strtolower($this->coreHelper->extractNodeVal($nodes));
     $type = $this->_isValidProductType($value) ? $value : Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
     $product->setTypeId($type)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true);
     return $type;
 }
Exemple #11
0
 public function addProduct($data)
 {
     $product = new Mage_Catalog_Model_Product();
     // Build the product
     $setId = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($this->typeId)->addFilter('attribute_set_name', $this->attributeSet['name'])->getFirstItem()->getId();
     // firstItem becouse of filter ($this->typeId) and filter ('attribute_set_name') design single attribute set.
     $product->setSku($data['sku']);
     $product->setAttributeSetId($setId);
     # 9 is for default
     $product->setTypeId('simple');
     $product->setName($data['name']);
     $product->setWebsiteIDs(array(1));
     //only array!!!!!  # Website id, 1 is default
     $product->setStoreIDs(array(0, 1));
     $product->setDescription($data['description']);
     $product->setShortDescription($data['short_description']);
     $product->setPrice($data['price']);
     # Set some price
     $product->setWeight($data['weight']);
     $product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
     $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
     $product->setTaxClassId(0);
     # default tax class
     if ($catId = $this->getCategoryIdByName($this->categoryName)) {
         $product->setCategoryIds(array($catId));
         # some cat id's,
     }
     $product->setStockData(array('is_in_stock' => 1, 'qty' => $data['qty']));
     $product->setCreatedAt(strtotime('now'));
     try {
         $product->save();
         echo "product created. ID: {$product->getId()} \n";
     } catch (Exception $ex) {
         zend_debug::dump($ex->getMessage());
     }
 }
Exemple #12
0
 /**
  * Set type id to combined to stop tax being displayed via Symmetrics_TweaksGerman_Block_Tax
  *
  * @param Mage_Catalog_Model_Product $oProduct
  */
 protected function setSymmetricsProductType(Mage_Catalog_Model_Product $oProduct)
 {
     if (Mage::helper('core')->isModuleEnabled('Symmetrics_TweaksGerman') && $oProduct->getTypeId() == 'bundle') {
         $oProduct->setTypeId('combined');
     }
 }
Exemple #13
0
 public function addProduct()
 {
     echo date("\nY-d-m H:i:s\n");
     //$this->query("TRUNCATE TABLE `cataloginventory_stock_status_idx`");
     $processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
     $processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
     $processes->walk('save');
     $connection = Mage::getModel('core/resource')->getConnection('core_read');
     //$product = Mage::getModel('catalog/product');
     $product = new Mage_Catalog_Model_Product();
     // get data array
     $select = $connection->select()->from('oberig_products');
     $result = $connection->query($select)->fetchAll();
     //(PDO::FETCH_ASSOC);  //mage::d($row); //echo $select->__toString();//die;//mage::D($result);
     //category mapping
     $result2 = array();
     foreach ($result as &$row) {
         if (empty($row['category_ids'])) {
             $row['category_ids'] = array();
             $result2[] = $row;
             continue;
         }
         $cats = explode(',', $row['category_ids']);
         foreach ($cats as &$cat) {
             $select = $connection->select()->from('oberig_category_mapping', 'new_cat_id')->where('old_cat_id=?', $cat);
             $res = $connection->query($select)->fetch();
             $cat = $res['new_cat_id'];
         }
         $row['category_ids'] = $cats;
         $result2[] = $row;
     }
     $result = $result2;
     foreach ($result as $row) {
         //mage::d($row['category_ids']);
         $product = new Mage_Catalog_Model_Product();
         // Build the product
         $product->setSku($row['sku']);
         $product->setAttributeSetId('4');
         # 9 is for default
         $product->setTypeId('simple');
         $product->setStatus(1);
         $product->setWebsiteIDs(array(1));
         $product->setCategoryIds($row['category_ids']);
         $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
         $product->setPrice($row['price']);
         $product->setData('store', $row['store']);
         //$product->setData('websites', $row['websites']);
         $product->setData('attribute_set', $row['attribute_set']);
         $product->setData('type', $row['type']);
         $product->setData('sku', $row['sku']);
         $product->setData('has_options', $row['has_options']);
         $product->setData('name', $row['name']);
         $product->setData('meta_title', $row['meta_title']);
         $product->setData('meta_description', $row['meta_description']);
         $product->setData('url_key', $row['url_key']);
         $product->setData('url_path', $row['url_path']);
         $product->setData('options_container', $row['options_container']);
         $product->setData('extra_title', $row['extra_title']);
         $product->setData('frame_gender', $row['frame_gender']);
         $product->setData('frame_shape', $row['frame_shape']);
         $product->setData('cost', $row['cost']);
         $product->setData('weight', $row['weight']);
         $product->setData('manufacturer', $row['manufacturer']);
         //$product->setData('status', $row['status']);
         $product->setData('tax_class_id', $row['tax_class_id']);
         //$product->setData('visibility', $row['visibility']);
         $product->setData('enable_googlecheckout', $row['enable_googlecheckout']);
         $product->setData('is_imported', $row['is_imported']);
         $product->setData('frame_type', $row['frame_type']);
         //$product->setData('sell_by_phone_only', $row['sell_by_phone_only']);
         $product->setData('description', $row['description']);
         $product->setData('short_description', $row['short_description']);
         $product->setData('meta_keyword', $row['meta_keyword']);
         $product->setData('special_from_date', $row['special_from_date']);
         $product->setData('min_qty', $row['min_qty']);
         $product->setData('use_config_min_qty', $row['use_config_min_qty']);
         $product->setData('is_qty_decimal', $row['is_qty_decimal']);
         $product->setData('backorders', $row['backorders']);
         $product->setData('use_config_backorders', $row['use_config_backorders']);
         $product->setData('min_sale_qty', $row['min_sale_qty']);
         $product->setData('use_config_min_sale_qty', $row['use_config_min_sale_qty']);
         $product->setData('max_sale_qty', $row['max_sale_qty']);
         $product->setData('use_config_max_sale_qty', $row['use_config_max_sale_qty']);
         $product->setData('low_stock_date', $row['low_stock_date']);
         $product->setData('notify_stock_qty', $row['notify_stock_qty']);
         $product->setData('use_config_notify_stock_qty', $row['use_config_notify_stock_qty']);
         $product->setData('manage_stock', $row['manage_stock']);
         $product->setData('use_config_manage_stock', $row['use_config_manage_stock']);
         $product->setData('stock_status_changed_automatically', $row['stock_status_changed_automatically']);
         $product->setData('use_config_qty_increments', $row['use_config_qty_increments']);
         $product->setData('qty_increments', $row['qty_increments']);
         $product->setData('use_config_enable_qty_increments', $row['use_config_enable_qty_increments']);
         $product->setData('enable_qty_increments', $row['enable_qty_increments']);
         $product->setData('product_name', $row['product_name']);
         $product->setData('store_id', $row['store_id']);
         $product->setData('product_type_id', $row['product_type_id']);
         $product->setData('product_status_changed', $row['product_status_changed']);
         $product->setData('product_changed_websites', $row['product_changed_websites']);
         $product->setData('custom_design', $row['custom_design']);
         $product->setData('page_layout', $row['page_layout']);
         $product->setData('image_label', $row['image_label']);
         $product->setData('small_image_label', $row['small_image_label']);
         $product->setData('thumbnail_label', $row['thumbnail_label']);
         $product->setData('gift_message_available', $row['gift_message_available']);
         $product->setData('framecolour', $row['framecolour']);
         $product->setData('special_price', $row['special_price']);
         $product->setData('is_recurring', $row['is_recurring']);
         $product->setData('frame_size', $row['frame_size']);
         $product->setData('custom_layout_update', $row['custom_layout_update']);
         $product->setData('special_to_date', $row['special_to_date']);
         $product->setData('news_from_date', $row['news_from_date']);
         $product->setData('news_to_date', $row['news_to_date']);
         $product->setData('custom_design_from', $row['custom_design_from']);
         $product->setData('custom_design_to', $row['custom_design_to']);
         $product->setData('stock_clearance', $row['stock_clearance']);
         $product->setData('lenstint', $row['lenstint']);
         $product->setData('framesizetest', $row['framesizetest']);
         $product->setStockData(array('is_in_stock' => $row['is_in_stock'], 'qty' => $row['qty']));
         $product->setIsMassupdate(false);
         try {
             $product->save();
             //Mage::getResourceSingleton('catalog/product_indexer_price')->reindexProductIds(array($productId));
             //Mage::register('current_product', $product);
             //$product = null;
         } catch (Exception $ex) {
             echo 'test\\n';
             echo $ex->getMessage();
             //Handle the error
         }
     }
     $processes->walk('reindexAll');
     $processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
     $processes->walk('save');
     $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
     if ($indexProcess) {
         $indexProcess->reindexAll();
     }
     echo date("\nY-d-m H:i:s\n");
 }
 public function CreateGeneralProducts()
 {
     try {
         $parent_category = Mage::getStoreConfig('oscommerceimportconf/mageconfiguration/conf_category', Mage::app()->getStore());
         $storeId = Mage::getStoreConfig('oscommerceimportconf/mageconfiguration/conf_website', Mage::app()->getStore());
         $AttributeSetId = Mage::getStoreConfig('oscommerceimportconf/mageconfiguration/conf_attribute', Mage::app()->getStore());
         /////////////////////////////////////////////////////////////////////////////////////
         // Create Custom Product for Import Shipping
         /////////////////////////////////////////////////////////////////////////////////////
         $pro_Model = 'osc-shipping';
         $pro_Name = 'Shipping';
         $oProduct = Mage::getModel("catalog/product")->getCollection()->setStoreId($storeId)->addAttributeToSelect("sku")->addFieldToFilter("sku", array('eq' => $pro_Model))->getFirstItem();
         if (sizeof($oProduct->getData()) == 0) {
             $product = new Mage_Catalog_Model_Product();
             // Build the product
             $product->setSku($pro_Model);
             $product->setAttributeSetId($AttributeSetId);
             $product->setTypeId('simple');
             $product->setName($pro_Name);
             $product->setCategoryIds($parent_category);
             $product->setWebsiteIDs(array($storeId));
             $product->setDescription('-');
             $product->setShortDescription('-');
             $product->setPrice(0);
             $product->setWeight(0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
             $product->setStatus(1);
             $product->setTaxClassId(0);
             # My default tax class
             $product->setStockData(array('is_in_stock' => 1, 'qty' => 10000));
             $product->setCreatedAt(strtotime('now'));
             $product->save();
         }
         /////////////////////////////////////////////////////////////////////////////////////
         // Create Custom Product for Import Discount
         /////////////////////////////////////////////////////////////////////////////////////
         $pro_Model = 'osc-discount';
         $pro_Name = 'Discount';
         $oProduct = Mage::getModel("catalog/product")->getCollection()->setStoreId($storeId)->addAttributeToSelect("sku")->addFieldToFilter("sku", array('eq' => $pro_Model))->getFirstItem();
         if (sizeof($oProduct->getData()) == 0) {
             $product = new Mage_Catalog_Model_Product();
             // Build the product
             $product->setSku($pro_Model);
             $product->setAttributeSetId($AttributeSetId);
             $product->setTypeId('simple');
             $product->setName($pro_Name);
             $product->setCategoryIds($parent_category);
             $product->setWebsiteIDs(array($storeId));
             $product->setDescription('-');
             $product->setShortDescription('-');
             $product->setPrice(0);
             $product->setWeight(0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
             $product->setStatus(1);
             $product->setTaxClassId(0);
             # My default tax class
             $product->setStockData(array('is_in_stock' => 1, 'qty' => 10000));
             $product->setCreatedAt(strtotime('now'));
             $product->save();
         }
         /////////////////////////////////////////////////////////////////////////////////////
         // Create Custom Product for Import Taxes
         /////////////////////////////////////////////////////////////////////////////////////
         $pro_Model = 'osc-tax';
         $pro_Name = 'Tax';
         $oProduct = Mage::getModel("catalog/product")->getCollection()->setStoreId($storeId)->addAttributeToSelect("sku")->addFieldToFilter("sku", array('eq' => $pro_Model))->getFirstItem();
         if (sizeof($oProduct->getData()) == 0) {
             $product = new Mage_Catalog_Model_Product();
             // Build the product
             $product->setSku($pro_Model);
             $product->setAttributeSetId($AttributeSetId);
             $product->setTypeId('simple');
             $product->setName($pro_Name);
             $product->setCategoryIds($parent_category);
             $product->setWebsiteIDs(array($storeId));
             $product->setDescription('-');
             $product->setShortDescription('-');
             $product->setPrice(0);
             $product->setWeight(0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
             $product->setStatus(1);
             $product->setTaxClassId(0);
             # My default tax class
             $product->setStockData(array('is_in_stock' => 1, 'qty' => 10000));
             $product->setCreatedAt(strtotime('now'));
             $product->save();
         }
         /////////////////////////////////////////////////////////////////////////////////////
         // Create Custom Product for Import Other
         /////////////////////////////////////////////////////////////////////////////////////
         $pro_Model = 'osc-other';
         $pro_Name = 'Other Charges';
         $oProduct = Mage::getModel("catalog/product")->getCollection()->setStoreId($storeId)->addAttributeToSelect("sku")->addFieldToFilter("sku", array('eq' => $pro_Model))->getFirstItem();
         if (sizeof($oProduct->getData()) == 0) {
             $product = new Mage_Catalog_Model_Product();
             // Build the product
             $product->setSku($pro_Model);
             $product->setAttributeSetId($AttributeSetId);
             $product->setTypeId('simple');
             $product->setName($pro_Name);
             $product->setCategoryIds($parent_category);
             $product->setWebsiteIDs(array($storeId));
             $product->setDescription('-');
             $product->setShortDescription('-');
             $product->setPrice(1);
             $product->setWeight(0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
             $product->setStatus(1);
             $product->setTaxClassId(0);
             # My default tax class
             $product->setStockData(array('is_in_stock' => 1, 'qty' => 10000));
             $product->setCreatedAt(strtotime('now'));
             $product->save();
         }
     } catch (Exception $ex) {
         //echo $ex->getMessage();
         Mage::getSingleton('core/session')->setErrorMSG('Creating Import Products: ' . $pro_Name . ' - ' . $ex->getMessage());
     }
 }
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId(10)->setAttributeSetId(4)->setName('Simple Product')->setSku('simple1')->setDescription('description')->setShortDescription('short description')->setOptionsContainer('container1')->setMsrpDisplayActualPriceType(Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_IN_CART)->setPrice(10)->setWeight(1)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setWebsiteIds(array(1))->setCateroryIds(array())->setStockData(array('use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1))->save();
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId(11)->setAttributeSetId(4)->setName('Simple Product2')->setSku('simple2')->setDescription('description')->setShortDescription('short description')->setEnableGooglecheckout(false)->setOptionsContainer('container1')->setMsrpEnabled(Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type_Enabled::MSRP_ENABLE_YES)->setMsrpDisplayActualPriceType(Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_ON_GESTURE)->setPrice(20)->setWeight(1)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setWebsiteIds(array(1))->setCateroryIds(array())->setStockData(array('use_config_manage_stock' => 1, 'qty' => 50, 'is_qty_decimal' => 0, 'is_in_stock' => 1))->save();
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId(12)->setAttributeSetId(4)->setName('Simple Product 3')->setSku('simple3')->setDescription('description')->setShortDescription('short description')->setMsrpEnabled(Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type_Enabled::MSRP_ENABLE_NO)->setPrice(30)->setWeight(1)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)->setWebsiteIds(array(1))->setCateroryIds(array())->setStockData(array('use_config_manage_stock' => 1, 'qty' => 140, 'is_qty_decimal' => 0, 'is_in_stock' => 1))->save();
Exemple #16
0
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Downloadable
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)->setId(1)->setAttributeSetId(4)->setWebsiteIds(array(1))->setName('Downloadable Product')->setSku('downloadable-product')->setPrice(10)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setDownloadableData(array('link' => array(array('title' => 'Downloadable Product Link', 'type' => Mage_Downloadable_Helper_Download::LINK_TYPE_URL, 'is_shareable' => Mage_Downloadable_Model_Link::LINK_SHAREABLE_CONFIG, 'link_url' => 'http://example.com/downloadable.txt', 'link_id' => 0, 'is_delete' => null))))->save();
Exemple #17
0
 protected function _createProducts($productsToCreateCount)
 {
     $skus = array();
     $initialProductCount = $this->_getProductCount();
     $randValues = array('general_name' => 'crife_Simple Product Required', 'general_sku' => 'wkdov_simple_sku_req_zuknf');
     // 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());
     for ($c = 0; $c < $productsToCreateCount; $c++) {
         array_walk_recursive($randValues, array($this, 'randomizeData'), array('general_name', 'general_sku'));
         $newProduct = new Mage_Catalog_Model_Product();
         $newProduct->setTypeId('simple');
         $newProduct->setCategoryIds(array(42));
         $newProduct->setWebsiteIDs(array(1));
         $newProduct->setWeight('1.000');
         $newProduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
         $newProduct->setStatus(1);
         $newProduct->setSku($randValues['general_sku']);
         $newProduct->setTaxClassId(0);
         $newProduct->setStoreId(Mage::app()->getStore()->getId());
         $newProduct->setAttributeSetId(9);
         $newProduct->setName($randValues['general_name']);
         $newProduct->setDescription('Description');
         $newProduct->setShortDescription('Short Description');
         $newProduct->setPrice(9.99);
         $newProduct->setStockData(array('is_in_stock' => 1, 'qty' => 99999));
         $newProduct->setCreatedAt(strtotime('now'));
         $newProduct->save();
         $skus[] = $randValues['general_sku'];
     }
     $finalProductCount = $this->_getProductCount();
     $this->assertEquals($productsToCreateCount, $finalProductCount - $initialProductCount);
     return $skus;
 }
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  Test
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$category = new Mage_Catalog_Model_Category();
$category->setId(3)->setName('Category 1')->setParentId(2)->setPath('1/2/3')->setLevel(2)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->setPosition(1)->save();
$urlKeys = array('url-key-', 'url-key-1', 'url-key-2', 'url-key-5', 'url-key-1000', 'url-key-999', 'url-key-asdf');
foreach ($urlKeys as $i => $urlKey) {
    $id = $i + 1;
    $product = new Mage_Catalog_Model_Product();
    $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId($id)->setStoreId(1)->setAttributeSetId(4)->setWebsiteIds(array(1))->setName('Simple Product ' . $id)->setSku('simple-' . $id)->setPrice(10)->setCategoryIds(array(3))->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setUrlKey($urlKey)->setUrlPath($urlKey . '.html')->save();
}
Exemple #19
0
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$product = new Mage_Catalog_Model_Product();
$product->setTypeId('simple')->setId(1)->setAttributeSetId(4)->setName('Simple Product')->setSku('simple')->setPrice(10)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save();
$customDesignProduct = new Mage_Catalog_Model_Product($product->getData());
$customDesignProduct->setId(2)->setCustomDesign('default/default/blue')->save();
Exemple #20
0
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Checkout
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
require __DIR__ . '/../../Checkout/_files/simple_product.php';
$bundleProduct = new Mage_Catalog_Model_Product();
$bundleProduct->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)->setId(3)->setAttributeSetId(4)->setWebsiteIds(array(1))->setName('Bundle Product')->setSku('bundle-product')->setDescription('Description with <b>html tag</b>')->setShortDescription('Bundle')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setStockData(array('use_config_manage_stock' => 0, 'manage_stock' => 0, 'use_config_enable_qty_increments' => 1, 'use_config_qty_increments' => 1, 'is_in_stock' => 0))->setBundleOptionsData(array(array('title' => 'Bundle Product Items', 'default_title' => 'Bundle Product Items', 'type' => 'select', 'required' => 1, 'delete' => '', 'position' => 0, 'option_id' => '')))->setBundleSelectionsData(array(array(array('product_id' => 1, 'selection_qty' => 1, 'selection_can_change_qty' => 1, 'delete' => '', 'position' => 0, 'selection_price_type' => 0, 'selection_price_value' => 0.0, 'option_id' => '', 'selection_id' => '', 'is_default' => 1))))->setCanSaveBundleSelections(true)->setAffectBundleProductSelections(true)->save();
/** @var $product Mage_Catalog_Model_Product */
$product = Mage::getModel('Mage_Catalog_Model_Product');
$product->load($bundleProduct->getId());
/** @var $typeInstance Mage_Bundle_Model_Product_Type */
//Load options
$typeInstance = $product->getTypeInstance();
$typeInstance->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $typeInstance->getOptionsCollection($product);
$selectionCollection = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
$bundleOptions = array();
$bundleOptionsQty = array();
/** @var $option Mage_Bundle_Model_Option */
foreach ($optionCollection as $option) {
    /** @var $selection Mage_Bundle_Model_Selection */
    $selection = $selectionCollection->getFirstItem();
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/* Create attribute */
$installer = new Mage_Catalog_Model_Resource_Setup('catalog_setup');
$attribute = new Mage_Catalog_Model_Resource_Eav_Attribute();
$attribute->setData(array('attribute_code' => 'test_configurable', 'entity_type_id' => $installer->getEntityTypeId('catalog_product'), 'is_global' => 1, 'is_user_defined' => 1, 'frontend_input' => 'select', 'is_unique' => 0, 'is_required' => 1, 'is_configurable' => 1, 'is_searchable' => 0, 'is_visible_in_advanced_search' => 0, 'is_comparable' => 0, 'is_filterable' => 0, 'is_filterable_in_search' => 0, 'is_used_for_promo_rules' => 0, 'is_html_allowed_on_front' => 1, 'is_visible_on_front' => 0, 'used_in_product_listing' => 0, 'used_for_sort_by' => 0, 'frontend_label' => array(0 => 'Test Configurable'), 'option' => array('value' => array('option_0' => array(0 => 'Option 1'), 'option_1' => array(0 => 'Option 2')), 'order' => array('option_0' => 1, 'option_1' => 2)), 'backend_type' => 'int'));
$attribute->save();
/* Assign attribute to attribute set */
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
/* Create simple products per each option */
$options = new Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection();
$options->setAttributeFilter($attribute->getId());
$attributeValues = array();
$productsData = array();
foreach ($options as $option) {
    $product = new Mage_Catalog_Model_Product();
    $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId($option->getId() * 10)->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))->setWebsiteIds(array(1))->setName('Configurable Option' . $option->getId())->setSku('simple_' . $option->getId())->setPrice(10)->setTestConfigurable($option->getId())->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setStockData(array('use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1))->save();
    $dataOption = array('label' => 'test', 'attribute_id' => $attribute->getId(), 'value_index' => $option->getId(), 'is_percent' => false, 'pricing_value' => 5);
    $productsData[$product->getId()] = array($dataOption);
    $attributeValues[] = $dataOption;
}
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->setId(1)->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))->setWebsiteIds(array(1))->setName('Configurable Product')->setSku('configurable')->setPrice(100)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setStockData(array('use_config_manage_stock' => 1, 'is_in_stock' => 1))->setConfigurableProductsData($productsData)->setConfigurableAttributesData(array(array('attribute_id' => $attribute->getId(), 'attribute_code' => $attribute->getAttributeCode(), 'frontend_label' => 'test', 'values' => $attributeValues)))->save();
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  Test
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/**
 * Products generation to test base data
 */
$testCases = (include dirname(__FILE__) . '/_algorithm_base_data.php');
$installer = new Mage_Catalog_Model_Resource_Setup('catalog_setup');
/**
 * After installation system has two categories: root one with ID:1 and Default category with ID:2
 */
$category = new Mage_Catalog_Model_Category();
$category->setId(3)->setName('Root Category')->setParentId(2)->setPath('1/2/3')->setLevel(2)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->setPosition(1)->save();
$lastProductId = 0;
foreach ($testCases as $index => $testCase) {
    $category = new Mage_Catalog_Model_Category();
    $position = $index + 1;
    $categoryId = $index + 4;
    $category->setId($categoryId)->setName('Category ' . $position)->setParentId(3)->setPath('1/2/3/' . $categoryId)->setLevel(3)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->setIsAnchor(true)->setPosition($position)->save();
    foreach ($testCase[0] as $price) {
        $product = new Mage_Catalog_Model_Product();
        $productId = $lastProductId + 1;
        $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId($productId)->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))->setStoreId(1)->setWebsiteIds(array(1))->setName('Simple Product ' . $productId)->setSku('simple-' . $productId)->setPrice($price)->setWeight(18)->setCategoryIds(array($categoryId))->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save();
        ++$lastProductId;
    }
}
Exemple #23
0
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  performance_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
// Extract product set id
$productResource = Mage::getModel('Mage_Catalog_Model_Product');
$entityType = $productResource->getResource()->getEntityType();
$sets = Mage::getResourceModel('Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection')->setEntityTypeFilter($entityType->getId())->load();
$setId = null;
foreach ($sets as $setInfo) {
    $setId = $setInfo->getId();
    break;
}
if (!$setId) {
    throw new Exception('No attributes sets for product found.');
}
// Create product
$product = new Mage_Catalog_Model_Product();
$product->setTypeId('simple')->setAttributeSetId($setId)->setWebsiteIds(array(1))->setName('Product 1')->setShortDescription('Product 1 Short Description')->setWeight(1)->setDescription('Product 1 Description')->setSku('product_1')->setPrice(10)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setTaxClassId(0)->save();
$stockItem = new Mage_CatalogInventory_Model_Stock_Item();
$stockItem->setProductId($product->getId())->setTypeId($product->getTypeId())->setStockId(Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID)->setIsInStock(1)->setQty(10000)->setUseConfigMinQty(1)->setUseConfigBackorders(1)->setUseConfigMinSaleQty(1)->setUseConfigMaxSaleQty(1)->setUseConfigNotifyStockQty(1)->setUseConfigManageStock(1)->setUseConfigQtyIncrements(1)->setUseConfigEnableQtyInc(1)->save();
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
require __DIR__ . '/product_image.php';
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId(1)->setAttributeSetId(4)->setWebsiteIds(array(1))->setName('Simple Product')->setSku('simple')->setPrice(10)->setDescription('Description with <b>html tag</b>')->setImage('/m/a/magento_image.jpg')->setSmallImage('/m/a/magento_image.jpg')->setThumbnail('/m/a/magento_image.jpg')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save();
Exemple #25
0
 public function importProducts($products, $storeId, $store)
 {
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     if (!empty($products)) {
         foreach ($products as $_product) {
             $update = false;
             if ($_product["code"]) {
                 $sku = $_product["code"];
             } elseif ($_product["code2"]) {
                 $sku = $_product["code2"];
             } else {
                 $sku = $_product["code3"];
             }
             $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
             if (!$product) {
                 $product = Mage::getModel('catalog/product')->load($_product["productID"]);
                 if (!$product->getName()) {
                     $product = new Mage_Catalog_Model_Product();
                     $product->setId($_product["productID"]);
                     Mage::helper('Erply')->log("Creating new product: " . $_product["productID"]);
                 } else {
                     Mage::helper('Erply')->log("Editing old product: " . $_product["productID"]);
                     $update = true;
                 }
             } else {
                 $update = true;
             }
             if ($_product["displayedInWebshop"] == 0) {
                 if ($update) {
                     try {
                         $product->delete();
                         Mage::helper('Erply')->log("Delete existing product which should be in webshop id: " . $_product["productID"] . " - sku: " . $sku);
                     } catch (Exception $e) {
                         Mage::helper('Erply')->log("Failed to delete product with message: " . $e->getMessage());
                     }
                 }
                 continue;
             }
             $product->setStoreId($storeId);
             // product does not exist so we will be creating a new one.
             $product->setIsMassupdate(true);
             $product->setExcludeUrlRewrite(true);
             $product->setTypeId('simple');
             $product->setWeight(1.0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
             $product->setStatus(1);
             $product->setSku($sku);
             $product->setTaxClassId(0);
             // set the rest of the product information here that can be set on either new/update
             if (!$update) {
                 $product->setAttributeSetId((int) Mage::getStoreConfig('eepohs_erply/product/attribute_set', $storeId));
                 // the product attribute set to use
             }
             $product->setName($_product["name"]);
             $category = Mage::getModel('catalog/category')->load($_product["groupID"]);
             if ($category->getName()) {
                 $product->setCategoryIds(array($_product["groupID"]));
                 // array of categories it will relate to
             }
             if (Mage::app()->isSingleStoreMode()) {
                 $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
             } else {
                 $product->setWebsiteIds(array($store->getWebsiteId()));
             }
             $product->setBatchPrices(array());
             $product->setStockPriorities(array());
             //$product->setPrice($_product["price"]);
             // set the product images as such
             // $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
             //        $image = '/path/to/magento/media/catalog/products/import/image.jpg';
             //
             //        $product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
             //        $product->addImageToMediaGallery ($image, array ('image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('small_image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('thumbnail'), false, false);
             // setting custom attributes. for example for a custom attribute called special_attribute
             // special_attribute will be used on all examples below for the various attribute types
             //$product->setSpecialAttribute('value here');
             // setting a Yes/No Attribute
             //        $product->setSpecialField(1);
             // setting a Selection Attribute
             //$product->setSpecialAttribute($idOfAttributeOption); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number.
             // setting a Mutli-Selection Attribute
             //$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that)
             //        $product->setData($data);
             if (isset($_product["attributes"])) {
                 $erplyAttributes = $_product["attributes"];
                 $mapping = unserialize(Mage::getStoreConfig('eepohs_erply/product/attributes', $storeId));
                 if (!empty($erplyAttributes) && !empty($mapping)) {
                     $mappings = array();
                     foreach ($mapping as $map) {
                         $mappings[$map["erply_attribute"]] = $map["magento_attribute"];
                     }
                     foreach ($erplyAttributes as $attribute) {
                         if (in_array($attribute["attributeName"], array_keys($mappings))) {
                             if ($attribute["attributeValue"]) {
                                 $product->setData($mappings[$attribute["attributeName"]], $attribute["attributeValue"]);
                             }
                         }
                     }
                 }
             }
             $product->save();
             Mage::helper('Erply')->log("Added: " . $product->getSku());
         }
     }
 }
Exemple #26
0
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$product = new Mage_Catalog_Model_Product();
$product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setId(1)->setAttributeSetId(4)->setName('New Product')->setSku('simple')->setPrice(10)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setWebsiteIds(array(1))->setStockData(array('qty' => 100, 'is_in_stock' => 1))->setNewsFromDate(date('Y-m-d', strtotime('-2 day')))->setNewsNewsToDate(date('Y-m-d', strtotime('+2 day')))->save();
 public function createBundleProduct(&$item, $asid)
 {
     $attributeSetModel = Mage::getModel('eav/entity_attribute_set');
     $attributeSetModel->load($asid);
     if (count($attributeSetModel) > 0) {
         $p_status = (string) $item->isActive == 'Y' ? 1 : 2;
         $p_taxclass = (string) $item->isTaxable == 'Y' ? 2 : 0;
         $product = new Mage_Catalog_Model_Product();
         $product->setTypeId('bundle');
         $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
         //New and created data code start
         $format = 'Y-m-d H:i:s';
         $catalogNewproductDays = Mage::getStoreConfig('catalog/newproduct/days', Mage::app()->getStore());
         if (!empty($catalogNewproductDays) && $catalogNewproductDays >= 0) {
             $currenDateTime = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
             $new_from_date = date($format, strtotime('1 days' . $currenDateTime));
             $new_to_date = date($format, strtotime($catalogNewproductDays . ' days' . $new_from_date));
             $product->setNewsFromDate($new_from_date);
             $product->setNewsToDate($new_to_date);
         }
         if ($product->getCreatedTime == NULL || $product->getUpdateTime() == NULL) {
             $product->setCreatedTime($currenDateTime)->setUpdateTime($currenDateTime);
         }
         //New and created data code end
         $product->setSku((string) $item->id);
         //Product custom id
         $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
         $product->setStoreIDs(array($this->_store_id));
         // Default store id .
         $product->setAttributeSetId($asid);
         $product->setData('name', (string) $item->name);
         $product->setPrice((double) $item->price);
         $splAmt = (array) $item->specialPrice->amount;
         if (isset($item->specialPrice->amount) && $item->specialPrice->amount != NULL) {
             if (!empty($splAmt)) {
                 $product->setSpecialPrice((double) $item->specialPrice->amount);
             }
             //special price in form 11.22
         }
         $fromDate = (array) $item->specialPrice->fromDateTime;
         if (isset($item->specialPrice->fromDateTime) && $item->specialPrice->fromDateTime != NULL) {
             if (!empty($fromDate)) {
                 $product->setSpecialFromDate(Mage::helper('customimport')->getCurrentLocaleDateTime($item->specialPrice->fromDateTime));
             }
             //special price from (MM-DD-YYYY)
         }
         $toDate = (array) $item->specialPrice->toDateTime;
         if (isset($item->specialPrice->toDateTime) && $item->specialPrice->toDateTime != NULL) {
             if (!empty($toDate)) {
                 $product->setSpecialToDate(Mage::helper('customimport')->getCurrentLocaleDateTime($item->specialPrice->toDateTime));
             }
             //special price to (MM-DD-YYYY)
         }
         $product->setWeight((double) $item->weight);
         $product->setStatus($p_status);
         $product->setTaxClassId($p_taxclass);
         $product->setDescription((string) $item->longDescription);
         $product->setShortDescription((string) $item->shortDescription);
         $product->setMetaTitle((string) $item->pageTitle);
         $product->setMetaKeyword((string) $item->metaKeywords);
         $product->setMetaDescription((string) $item->metaDescription);
         $product->setExternalImage((string) $item->originalImageUrl);
         $product->setExternalSmallImage((string) $item->largeImageUrl);
         $product->setExternalThumbnail((string) $item->smallImageUrl);
         $product->setShipmentType(0);
         //shipment type (0 - together, 1 - separately
         try {
             Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
             $product->save();
             $stockItem = Mage::getModel('cataloginventory/stock_item');
             $stockItem->assignProduct($product);
             $stockItem->setData('stock_id', (int) 1);
             $stockItem->setData('use_config_manage_stock', (int) 1);
             $stockItem->setData('min_qty', (int) 0);
             $stockItem->setData('is_decimal_divided', (int) 0);
             $stockItem->setData('qty', (int) 0);
             $stockItem->setData('use_config_min_qty', 1);
             $stockItem->setData('use_config_backorders', 1);
             $stockItem->setData('min_sale_qty', 1);
             $stockItem->setData('use_config_min_sale_qty', 1);
             $stockItem->setData('use_config_max_sale_qty', 1);
             $stockItem->setData('is_in_stock', 1);
             $stockItem->setData('use_config_notify_stock_qty', 1);
             // Added Manage Stock Functionality
             // Manage Stock
             $inventory = $item->inventory;
             $manageItem = (string) strtoupper($inventory->manageStock);
             if ($manageItem == 'N') {
                 $stockItem->setData('use_config_manage_stock', 0);
                 $stockItem->setData('manage_stock', 0);
             }
             $stockItem->save();
             $stockStatus = Mage::getModel('cataloginventory/stock_status');
             $stockStatus->assignProduct($product);
             $stockStatus->saveProductStatus($product->getId(), 1);
         } catch (Exception $e) {
             $this->customHelper->reportError($e->getMessage());
             $this->customHelper->sendLogEmail($this->logPath);
         }
     } else {
         $this->customHelper->reportError($this->customHelper->__('Attribute set ID # %s is missing. Hence skipped product # %s', $asid, $item->id));
     }
 }
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  Test
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/* Create attribute */
$installer = new Mage_Catalog_Model_Resource_Setup('catalog_setup');
$attribute = new Mage_Catalog_Model_Resource_Eav_Attribute();
$attribute->setData(array('attribute_code' => 'attribute_with_option', 'entity_type_id' => $installer->getEntityTypeId('catalog_product'), 'is_global' => 1, 'frontend_input' => 'select', 'is_filterable' => 1, 'option' => array('value' => array('option_0' => array(0 => 'Option Label'))), 'backend_type' => 'int'));
$attribute->save();
/* Assign attribute to attribute set */
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
/* Create simple products per each option */
$options = new Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection();
$options->setAttributeFilter($attribute->getId());
foreach ($options as $option) {
    $product = new Mage_Catalog_Model_Product();
    $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))->setWebsiteIds(array(1))->setName('Simple Product ' . $option->getId())->setSku('simple_product_' . $option->getId())->setPrice(10)->setCategoryIds(array(2))->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setStockData(array('use_config_manage_stock' => 1, 'qty' => 5, 'is_in_stock' => 1))->save();
    Mage::getSingleton('Mage_Catalog_Model_Product_Action')->updateAttributes(array($product->getId()), array($attribute->getAttributeCode() => $option->getId()), $product->getStoreId());
}
Exemple #29
0
        $sku = $argv[1];
        break;
    }
    echo "\nEnter SKU: ";
    $sku = trim(fgets(STDIN));
}
$connection = Mage::getModel('core/resource')->getConnection('core_read');
$product = new Mage_Catalog_Model_Product();
$typeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
$setId = Mage::getModel('eav/entity_attribute_set')->getCollection()->setEntityTypeFilter($typeId)->addFilter('attribute_set_name', 'Default')->getFirstItem()->getId();
//$setId = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($typeId)->addFilter('attribute_set_name', 'Default')->getFirstItem()->getId();
// Build the product
$product->setSku($sku);
$product->setAttributeSetId($setId);
# 9 is for default
$product->setTypeId('simple');
$product->setName('Lens 1');
$product->setCategoryIds(array(3));
# some cat id's,
$product->setWebsiteIDs(array(0, 1));
//only array!!!!!  # Website id, 1 is default
$product->setStoreIDs(array(0, 1));
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');
$product->setPrice(39.99);
# Set some price
$product->setWeight(4.0);
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$product->setTaxClassId(0);
# default tax class
 /**
  * given a DOMNodeList and a Mage_Catalog_Model_Product make sure this is
  * a product of type configurable and then extract the configurable attribute from the node list
  * then get the configurable attribute array for each configured attributes
  * @param DOMNOdeList $nodes the node with configurableAttributes data
  * @param Mage_Catalog_Model_Product $product
  * @return array | null an array of configurable attribute data if the given product is configurable otherwise null
  */
 public function extractConfigurableAttributesData(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     // We are ensuring that the given product is a parent configurable product by first checking if the product sku
     // doesn't match the product style id. If this condition is met then we know we have a child product and we won't
     // proceed otherwise we know we have a parent product and proceed continue.
     if ($product->getSku() !== $this->_normalizeStyleId($product->getStyleId())) {
         return null;
     }
     $typeInstance = $product->getTypeInstance(true);
     // making sure the right type instance is set on the product
     if (!$typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) {
         $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true);
     }
     $data = null;
     // purposely setting this to null just in cause all the attribute already exists
     // we need to know which configurable attribute we already have for this product
     // so that we don't try to create the same super attribute relationship which will
     // cause unique key duplication SQL constraint to be thrown
     $existedData = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
     foreach (explode(',', strtolower(Mage::helper('eb2ccore')->extractNodeVal($nodes))) as $attributeCode) {
         // if we don't currently have a super attribute relationship then get the
         // configurable attribute data
         if (!$this->_isSuperAttributeExists($existedData, $attributeCode) && $this->_isAttributeInSet($attributeCode, $product)) {
             $data[] = $this->_getConfiguredAttributeData($attributeCode);
         }
     }
     // At this point we know we are dealing with a configurable product; therefore,
     // this is the right place to make sure manage stock get turn off.
     $this->_turnOffManageStock($product);
     return $data;
 }