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()); } }
// 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 $product->setStockData(array('is_in_stock' => 1, 'qty' => 99999)); $product->setCreatedAt(strtotime('now')); try { $product->save(); echo "product created"; } catch (Exception $ex) { zend_debug::dump($ex->getMessage()); } echo date("\nY-d-m H:i:s\n"); ?>
public function setPaths() { $collection = Mage::getModel('catalog/category')->getCollection(); foreach ($collection as $category) { $category->load(); $pathArr = explode("/", $category->getPath()); foreach ($pathArr as &$node) { if (end($pathArr) == $node) { break; } $node = $this->getCategoryIdByName($node); } unset($node); $path = implode("/", $pathArr); $category->setPath($path); try { $category->save(); } catch (Exception $e) { zend_debug::dump($e); return; } } }
public function csvAction() { $dump = Mage::helper('pdfinvoiceplus/localization')->translate('Shipping & Handling'); zend_debug::dump($dump); die; $p = 'magestore\\pdfinvoiceplus\\localization\\localization_england.csv'; $path = str_replace(array('\\', '/'), DS, $p); $file = Mage::getBaseDir('media') . DS . $path; $csv = new Varien_File_Csv(); $data = $csv->getDataPairs($file); zend_debug::dump($data); die; // die($file); $csv = scandir($file); $data = array(); foreach ($csv as $file) { if (preg_match('/^localization/', $file)) { $data[] = $file; } } zend_debug::dump($data); die; for ($i = 1; $i < count($data); $i++) { var_dump($data[$i]); } }
/** * CRM REPORTS * **/ public function getSampleRptDetail() { if ($this->getRequest()->getPost()) { $objOrderCollection = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*'); $objOrderCollection->addFieldToFilter('lead_status', array('in' => array('converted', 'unconverted'))); if ($this->getRequest()->getPost('date_range')) { $dateRangeArrayOrstring = $this->getDateRangeOrCutomRange(); if (is_array($dateRangeArrayOrstring)) { $objOrderCollection->addAttributeToFilter('main_table.created_at', array('from' => $dateRangeArrayOrstring['from_date'], 'to' => $dateRangeArrayOrstring['to_date'])); } else { $objOrderCollection->addAttributeToFilter('main_table.created_at', array('eq' => $dateRangeArrayOrstring)); } } else { if ($this->getRequest()->getPost('from_date') != '' && $this->getRequest()->getPost('to_date') != '') { $objOrderCollection->addAttributeToFilter('main_table.created_at', array('from' => Mage::getModel('core/date')->date('Y-m-d', strtotime($this->getRequest()->getPost('from_date'))), 'to' => Mage::getModel('core/date')->date('Y-m-d', strtotime($this->getRequest()->getPost('to_date'))))); } } if ($this->getRequest()->getPost('sample_type') != '') { if ($this->getRequest()->getPost('sample_type') == 'paid') { $objOrderCollection->addFieldToFilter('base_grand_total', array('gt' => 0)); } else { $objOrderCollection->addFieldToFilter('base_grand_total', array('eq' => 0)); } } if ($this->getRequest()->getPost('user')) { $objOrderCollection->addFieldToFilter('advisor', trim($this->getRequest()->getPost('user'))); } if ($this->getRequest()->getPost('call_status')) { $objOrderCollection->addFieldToFilter('call_status', trim($this->getRequest()->getPost('call_status'))); } zend_debug::dump($objOrderCollection->getdata()); return $objOrderCollection; //->getData(); } }
public static function vs($var) { return zend_debug::dump(get_class_vars($var)); }