Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Hna ketn3ayto 3la magento */
- $mageFilename = 'app/Mage.php';
- require_once $mageFilename;
- Mage::setIsDeveloperMode(true);
- ini_set('display_errors', 1);
- umask(0);
- Mage::app('admin');
- Mage::register('isSecureArea', 1);
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
- set_time_limit(0);
- ini_set('memory_limit','1024M');
- /* -------------------------------- */
- /* Hna ken3ayto 3la csv */
- $csv = new Varien_File_Csv();
- $data = $csv->getData('potsgrilled.csv'); //csv
- array_shift($data); /* Hadi kethayd line lewla li fiha les attribute "Nom,sku,......." */
- $message = '';
- $count = 1;
- foreach($data as $_data){
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
- $product = Mage::getModel('catalog/product');
- if(!$product->getIdBySku($_data[1].$count)){
- if( $_data[3] == "0%" ){
- $taxid = 2;
- $prix = $_data[2];
- } elseif ($_data[3] == "10%") {
- $taxid = 5;
- $prix = $_data[2] - ($_data[2] * (10/100)) ;
- }
- elseif ($_data[3] == "20%") {
- $taxid = 6;
- $prix = $_data[2] - ($_data[2] * (20/100));
- }
- else{
- $taxid = 2;
- $prix = $_data[2];
- }
- try{
- $product
- ->setStoreId(1) // Hna dir store id ghatl9ah f url diya System -> gestion de magasin -> Main Store
- ->setWebsiteIds(array(1)) //Hna dir Website id ghatl9ah f url diya System -> gestion de magasin -> Main Website khliha Array()
- ->setAttributeSetId(4) //Hna dir id diyal attrubite set ghatl9aha f url diyal Catalog -> Attribute -> 2 -> default
- ->setTypeId('simple') //product type
- ->setCreatedAt(strtotime('now')) //product creation time
- ->setSku($_data[1].$count) //SKU
- ->setName($_data[0]) //product name
- ->setWeight($_data[5]) // Hna Grammage
- ->setColisage($_data[4]) // Hna Colisage
- ->setStatus(1) //product status (1 - enabled, 2 - disabled) khliha 1 y3ni active
- ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) //catalog and search visibility khliha fhal haka
- ->setNewsFromDate('04/05/2018') //product set as new from
- ->setNewsToDate('12/30/2018') //product set as new to
- ->setPrice($prix) //Hna l prix
- ->setMetaTitle($_data[0]) // Hna meta title li kikon f head
- ->setMetaKeyword($_data[0]) // Hna meta keyword li kikon f head
- ->setMetaDescription($_data[0]) // Hna meta description li kikon f head
- ->setTaxClassId($taxid) // Classe diyal TAX diyal produit
- ->setDescription($_data[0]) // Hna Description diyal produit
- ->setShortDescription($_data[0]) // Hna Short description
- ->setMediaGallery (array('images'=>array (), 'values'=>array ())) //Hna Image diyal produit li htiti f media/import
- ->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . DS . $_data[1] . '.png', array('image','thumbnail','small_image'), false, false) //Hna ghadi twli hadik l'image hiya li f thumbnail o small*/
- /*addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . DS . $_data[1] . '.png', array('image','thumbnail','small_image'), false, false)*/
- ->setStockData(array(
- 'is_in_stock' => 1, //Hna disponibility
- 'qty' => 999 //Hna Quentity
- )
- )
- ->setCategoryIds(array(2,21)); //Hna les id diyal les category li ghadi ikon fihom lproduit
- $product->save();
- $count++;
- echo "goood";
- }catch(Exception $e){
- echo Mage::log($e->getMessage()) . " Message mabanch";
- }
- }
- else{
- echo "sorry";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment