Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function _createProduct($type, $doSave=true, $originalProduct, $newImagePath="")
- {
- // required for some versions
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
- $product = Mage::getModel('catalog/product');
- // add product images
- $images = array(
- 'thumbnail' => 'image.png',
- );
- foreach ($images as $imageType => $imageFileName) {
- if($newImagePath != ""){
- $dir = Mage::getBaseDir('media') . DS . 'custom_product_preview/quote/';
- $path = $dir . $newImagePath;
- }else{
- $dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
- $path = $dir . $imageFileName;
- }
- //echo $path."<br>";
- if (file_exists($path)) {
- try {
- $product->addImageToMediaGallery($path, $imageType, false);
- } catch (Exception $e) {
- echo $e->getMessage();
- }
- } else {
- echo "Can not find image by path: `{$path}`<br/>";
- }
- }
- $customerId = Mage::getSingleton('customer/session')->getCustomerId();
- $product->setCreatedByCustomerId($customerId);
- //$emaildate = Mage::getModel('core/date')->date('Y-m-d H:i:s');
- // $emaildate = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
- $emaildate = Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s');
- $emailimage = Mage::helper('catalog/image')->init($product, 'thumbnail');
- if ($doSave)
- $product->save();
- // To save inside my_designs
- $data = array('title'=>fav1_id,'product_id'=>$product->getId(),
- 'customer_id'=> $customerId , 'store_id' => 1 , 'created_at' => $emaildate , 'value'=> $emailimage );
- $model = Mage::getModel('example/mydesign')->setData($data);
- try
- {
- $fav1_id = $model->save()->getId();
- //echo "Custom Design saved successfully";
- } catch (Exception $e)
- {
- echo $e->getMessage();
- }
- // To save inside my_designs end
- return $product;
- }
Add Comment
Please, Sign In to add comment