Advertisement
Guest User

Untitled

a guest
Sep 10th, 2017
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.69 KB | None | 0 0
  1. public function newpostAction()
  2. {
  3. /**
  4. * Check license key
  5. */
  6. Mage::helper('marketplace')->checkMarketplaceKey();
  7. /**
  8. * Initilize customer and seller group id
  9. */
  10. $customerGroupId = $sellerGroupId = $customerStatus = '';
  11. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  12. $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
  13. $sellerGroupId = Mage::helper('marketplace')->getGroupId();
  14. $customerStatus = Mage::getSingleton('customer/session')->getCustomer()->getCustomerstatus();
  15. if (!$this->_getSession()->isLoggedIn() && $customerGroupId != $sellerGroupId) {
  16. Mage::getSingleton('core/session')->addError($this->__('You must have a Seller Account to access this page'));
  17. $this->_redirect('marketplace/seller/login');
  18. return;
  19. }
  20. /**
  21. * Checking whether customer approved or not
  22. */
  23. if ($customerStatus != 1) {
  24. Mage::getSingleton('core/session')->addError($this->__('Admin Approval is required. Please wait until admin confirms your Seller Account'));
  25. $this->_redirect('marketplace/seller/login');
  26. return;
  27. }
  28. /**
  29. * Initializing variables
  30. */
  31. $productNameTrim = $set = $setbase = $type = $store = $sellerId = '';
  32. /**
  33. * Getting product values
  34. */
  35. $type = $this->getRequest()->getPost('type');
  36. /**
  37. * Attribute set
  38. */
  39. $set = $this->getRequest()->getPost('set');
  40. $setbase = $this->getRequest()->getPost('setbase');
  41. $store = $this->getRequest()->getPost('store');
  42. if (Mage::getSingleton('customer/session')->isLoggedIn()) {
  43. $sellerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
  44. }
  45. /**
  46. * Getting group id
  47. */
  48. $groupId = Mage::helper('marketplace')->getGroupId();
  49. /**
  50. * Getting product data from product array
  51. */
  52. $productData = $this->getRequest()->getPost('product');
  53.  
  54. $silkType = $productData['silktype'];
  55.  
  56. /**
  57. * Getting product categories from category_ids array
  58. */
  59. $categoryIds = $this->getRequest()->getPost('category_ids');
  60. if (!empty($productData['name']) && !empty($productData['description']) && isset($productData['price']) && isset($productData['stock_data']['qty']) && !empty($type)) {
  61. /**
  62. * Initilize product weight
  63. */
  64. if ($type == 'simple') {
  65. if (!isset($productData['weight'])) {
  66. $productData['weight'] = 0;
  67. }
  68. }
  69. /**
  70. * Assing product short description
  71. */
  72. if (!empty($productData['short_description'])) {
  73. $productData['short_description'] = $productData['short_description'];
  74. }
  75. /**
  76. * Assign create at time
  77. */
  78. $createdAt = Mage::getModel('core/date')->gmtDate();
  79.  
  80. /**
  81. * Getting instance for catalog product collection
  82. */
  83. $product = Mage::getModel('catalog/product');
  84. /**
  85. * Initialize product sku
  86. */
  87.  
  88. if (isset($productData['sku'])) {
  89. $skuProductId = Mage::getModel('catalog/product')
  90. ->getIdBySku(trim($productData['sku']));
  91. if (!empty($skuProductId)) {
  92. /**
  93. * Error message redirect to create new product page
  94. */
  95. Mage::getSingleton('core/session')->addError($this->__('SKU Not Available'));
  96. $this->_redirect('marketplace/product/new/');
  97. return;
  98. }
  99. }
  100.  
  101.  
  102. /**
  103. * Initialize product attribute set id
  104. */
  105. if (!empty($set)) {
  106. $product->setAttributeSetId($set);
  107. } else {
  108. $sDefaultAttributeSetId = Mage::getSingleton('eav/config')
  109. ->getEntityType(Mage_Catalog_Model_Product::ENTITY)
  110. ->getDefaultAttributeSetId();
  111. $product->setAttributeSetId($sDefaultAttributeSetId);
  112. }
  113.  
  114. /**
  115. * Initialize product type
  116. */
  117. if (isset($type)) {
  118. $product->setTypeId($type);
  119. }
  120.  
  121.  
  122. /**
  123. * Initialize product categories
  124. */
  125. if (isset($categoryIds)) {
  126. $product->setCategoryIds($categoryIds);
  127. }
  128. $product->setSilktype($silkType);
  129.  
  130. /**
  131. * Storing product data's to all store view
  132. */
  133. $product->setStoreId(0);
  134.  
  135. /**
  136. * Initialize product create at time
  137. */
  138. if (isset($createdAt)) {
  139. $product->setCreatedAt($createdAt);
  140. }
  141. /**
  142. * Initialize seller id
  143. */
  144. if (isset($sellerId)) {
  145. $product->setSellerId($sellerId);
  146. }
  147.  
  148. /**
  149. * Initialize group id
  150. */
  151. if (isset($groupId)) {
  152. $product->setGroupId($groupId);
  153. }
  154.  
  155. /**
  156. * Set is assign product
  157. */
  158. $product->setIsAssignProduct(0);
  159.  
  160. $uploadsData = new Zend_File_Transfer_Adapter_Http();
  161. $filesDataArray = $uploadsData->getFileInfo();
  162.  
  163. /**
  164. * Checking whether image exist or not
  165. */
  166. if (!empty($filesDataArray)) {
  167. foreach ($filesDataArray as $key => $value) {
  168. /**
  169. * Initilize file name
  170. */
  171. $filename = $key;
  172.  
  173. if (substr($key, 0, 5) == 'image') {
  174. if (isset($filesDataArray[$filename]['name']) && (file_exists($filesDataArray[$filename]['tmp_name']))) {
  175. try {
  176. $imagesPath[] = Mage::helper('marketplace/marketplace')->uploadImage($filename, $filesDataArray);
  177. } catch (Exception $e) {
  178. /**
  179. * Display error message for images upload
  180. */
  181. Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
  182. }
  183. }
  184. }
  185. }
  186. }
  187.  
  188. /**
  189. * Adding Product images
  190. */
  191. if (!empty($imagesPath)) {
  192. $product->setMediaGallery(array('images' => array(), 'values' => array()));
  193. foreach ($imagesPath as $value) {
  194. $product->addImageToMediaGallery($value, array('image', 'small_image', 'thumbnail'), false, false);
  195. }
  196. }
  197.  
  198.  
  199. /**
  200. * Initialize dispatch event for product prepare
  201. */
  202. Mage::dispatchEvent(
  203. 'catalog_product_prepare_save', array('product' => $product, 'request' => $this->getRequest())
  204. );
  205.  
  206. /**
  207. * Assign configurable product data
  208. */
  209. if ($type == 'configurable') {
  210. $attributeIds = $this->getRequest()->getPost('attributes');
  211. $isInStock = 1;
  212. if (isset($productData['stock_data']['is_in_stock'])) {
  213. $isInStock = $productData['stock_data']['is_in_stock'];
  214. }
  215. $productData['stock_data'] = array();
  216. if (count($attributeIds) >= 1) {
  217. $attributeIds = array_unique($attributeIds);
  218. $product->getTypeInstance()->setUsedProductAttributeIds($attributeIds);
  219. $configurableAttributesData = $product->getTypeInstance()->getConfigurableAttributesAsArray();
  220. $product->setCanSaveConfigurableAttributes(true);
  221. $product->setConfigurableAttributesData($configurableAttributesData);
  222. $product->setConfigurableProductsData(array());
  223. }
  224. }
  225.  
  226. /**
  227. * Adding data to product instanse
  228. */
  229. if (!empty($productData)) {
  230. $product->addData($productData);
  231. }
  232. /**
  233. * Saving new product
  234. */
  235. try {
  236. $product->save();
  237.  
  238. if ($type == 'configurable') {
  239. $stockItem = Mage::getModel('cataloginventory/stock_item');
  240. $stockItem->assignProduct($product);
  241. $stockItem->setData('stock_id', 1);
  242. if (isset($productData['stock_data']['qty'])) {
  243. $stockItem->setData('qty', $productData['stock_data']['qty']);
  244. } else {
  245. $stockItem->setData('qty', 0);
  246. }
  247. $stockItem->setData('use_config_min_qty', 1);
  248. $stockItem->setData('use_config_backorders', 1);
  249. $stockItem->setData('min_sale_qty', 1);
  250. $stockItem->setData('use_config_min_sale_qty', 1);
  251. $stockItem->setData('use_config_max_sale_qty', 1);
  252. $stockItem->setData('is_in_stock', $isInStock);
  253. $stockItem->setData('use_config_notify_stock_qty', 1);
  254. $stockItem->setData('manage_stock', 1);
  255. $stockItem->save();
  256.  
  257. //This section is what was required.
  258. $stockStatus = Mage::getModel('cataloginventory/stock_status');
  259. $stockStatus->assignProduct($product);
  260. $stockStatus->saveProductStatus($product->getId(), 1);
  261. }
  262.  
  263. $productId = $product->getId();
  264.  
  265. /**
  266. * Load the product
  267. */
  268. $product = Mage::getModel('catalog/product')->load($productId);
  269. /**
  270. * Get all images
  271. */
  272. $mediaGallery = $product->getMediaGallery();
  273. /**
  274. * If there are images
  275. */
  276. if (isset($mediaGallery['images']) && !empty($store)) {
  277. /**
  278. * Loop through the images
  279. */
  280. $increment = 0;
  281. foreach ($mediaGallery['images'] as $image) {
  282. /**
  283. * Set the first image as the base image
  284. */
  285. if ($increment == $setbase) {
  286. $product->setStoreId($store)
  287. ->setImage($image['file'])
  288. ->setSmallImage($image['file'])
  289. ->setThumbnail($image['file']);
  290.  
  291. $product->save();
  292. }
  293. $increment++;
  294. /**
  295. * Stop
  296. */
  297.  
  298. }
  299.  
  300. }
  301.  
  302. /**
  303. * Initialize product options
  304. */
  305. if (!empty($productData['options'])) {
  306. $product->setProductOptions($productData['options']);
  307. $product->setCanSaveCustomOptions(1);
  308. $product->save();
  309. }
  310.  
  311. /**
  312. * Checking whether image or not
  313. */
  314. if (!empty($imagesPath)) {
  315. foreach ($imagesPath as $deleteImage) {
  316. /**
  317. * Checking whether image exist or not
  318. */
  319. if (file_exists($deleteImage)) {
  320. /**
  321. * Delete images from temporary folder
  322. */
  323. unlink($deleteImage);
  324. }
  325. }
  326. }
  327.  
  328. /**
  329. * Function for adding downloadable product sample and link data
  330. */
  331. $downloadProductId = $product->getId();
  332. if ($type == 'downloadable' && isset($downloadProductId) && isset($store)) {
  333. $this->addDownloadableProductData($downloadProductId, $store);
  334. }
  335.  
  336. /**
  337. * Success message redirect to manage product page
  338. */
  339. if (Mage::helper('marketplace')->getProductApproval() == 1) {
  340. Mage::getSingleton('core/session')->addSuccess($this->__('Your product is added successfully'));
  341. $mail = Mage::getModel('core/email');
  342. /*$mail = Mage::getModel('core/email');
  343. $mail->setToName('User');
  344. $mail->setToEmail('testmail98@gmail.com');
  345. $mail->setBody('Send Test mail to you.....');
  346. $mail->setSubject('Test Mail');
  347. $mail->setFromEmail('testmail@gmail.com');
  348. $mail->setFromName("Send Test mail to you.....");
  349. $mail->setType('html');// YOu can use Html or text as Mail format
  350. $mail->send(); */
  351.  
  352. $sellerData = Mage::getSingleton('customer/session')->getCustomer();
  353. $sellerIdss = $sellerData->getId();
  354. $seller_mail = $sellerData->getEmail();
  355.  
  356. $collectionss = Mage::getModel('followup/followup')->getCollection()
  357. ->addFieldToFilter('seller_id', $sellerIdss)
  358. ->addFieldToFilter('seller_email', $seller_mail);
  359.  
  360. foreach ($collectionss as $item) {
  361. $mycustomer_email = $item->getCustomerEmail();
  362. $mycustomer_name = $item->getCustomerName();
  363.  
  364. $template_id = 'customer_update';
  365. $email_to = $mycustomer_email;
  366. $customer_name = $cus_name;
  367. $email_template = Mage::getModel('core/email_template')->loadDefault($template_id);
  368. $custom_variable = $mycustomer_name;
  369. //$custom_variable1 = $cus_email;
  370. $custom_variable1 = $this->getRequest()->getPost('store_name');
  371. $email_template_variables = array(
  372. 'custom_variable' => $custom_variable,
  373. 'custom_variable1' => $custom_variable1);
  374. //'custom_variable2' => $custom_variable2);
  375. $sender_name = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
  376. $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
  377. $email_template->setSenderName($sender_name);
  378. $email_template->setSenderEmail($sender_email);
  379. $email_template->send($email_to, $customer_name, $email_template_variables);
  380.  
  381. }
  382.  
  383. if (Mage::getStoreConfig('marketplace/product/addproductemailnotification') == 1) {
  384. /**
  385. * Sending email for added new product
  386. */
  387. $templateId = (int)Mage::getStoreConfig('marketplace/product/addproductemailnotificationtemplate');
  388. $adminEmailId = Mage::getStoreConfig('marketplace/marketplace/admin_email_id');
  389. $toMailId = Mage::getStoreConfig("trans_email/ident_$adminEmailId/email");
  390. $toName = Mage::getStoreConfig("trans_email/ident_$adminEmailId/name");
  391.  
  392. /**
  393. * Selecting template id
  394. */
  395. if ($templateId) {
  396. $emailTemplate = Mage::getModel('core/email_template')->load($templateId);
  397. } else {
  398. $emailTemplate = Mage::getModel('core/email_template')
  399. ->loadDefault('marketplace_product_addproductemailnotificationtemplate');
  400. }
  401. $customer = Mage::getModel('customer/customer')->load($sellerId);
  402. $selleremail = $customer->getEmail();
  403. $recipient = $toMailId;
  404. $sellername = $customer->getName();
  405. $productname = $product->getName();
  406. $producturl = $product->getProductUrl();
  407. $emailTemplate->setSenderName($sellername);
  408. $emailTemplate->setSenderEmail($selleremail);
  409. $emailTemplateVariables = (array('ownername' => $toName, 'sellername' => $sellername, 'selleremail' => $selleremail, 'productname' => $productname, 'producturl' => $producturl));
  410. $emailTemplate->setDesignConfig(array('area' => 'frontend'));
  411. $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
  412. $emailTemplate->send($recipient, $sellername, $emailTemplateVariables);
  413.  
  414.  
  415. }
  416. } else {
  417. Mage::getSingleton('core/session')->addSuccess($this->__('Your product is awaiting moderation'));
  418. /*$mail = Mage::getModel('core/email');
  419. $mail->setToName('User');
  420. $mail->setToEmail('testmail98@gmail.com');
  421. $mail->setBody('Send Test mail to you.....');
  422. $mail->setSubject('Test Mail');
  423. $mail->setFromEmail('testmail@gmail.com');
  424. $mail->setFromName("Send Test mail to you.....");
  425. $mail->setType('html');// YOu can use Html or text as Mail format
  426. $mail->send(); */
  427.  
  428. foreach ($collectionss as $item) {
  429. $mycustomer_email = $item->getCustomerEmail();
  430. $mycustomer_name = $item->getCustomerName();
  431.  
  432. $template_id = 'customer_update';
  433. $email_to = $mycustomer_email;
  434. $customer_name = $cus_name;
  435. $email_template = Mage::getModel('core/email_template')->loadDefault($template_id);
  436. $custom_variable = $mycustomer_name;
  437. //$custom_variable1 = $cus_email;
  438. $custom_variable1 = $this->getRequest()->getPost('store_name');
  439. $email_template_variables = array(
  440. 'custom_variable' => $custom_variable,
  441. 'custom_variable1' => $custom_variable1);
  442. //'custom_variable2' => $custom_variable2);
  443. $sender_name = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
  444. $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
  445. $email_template->setSenderName($sender_name);
  446. $email_template->setSenderEmail($sender_email);
  447. $email_template->send($email_to, $customer_name, $email_template_variables);
  448.  
  449. }
  450.  
  451. if (Mage::getStoreConfig('marketplace/product/addproductemailnotification') == 1) {
  452. /**
  453. * Sending email for added new product
  454. */
  455. $templateId = (int)Mage::getStoreConfig('marketplace/product/addproductapprovalemailnotificationtemplate');
  456. $adminEmailId = Mage::getStoreConfig('marketplace/marketplace/admin_email_id');
  457. $toMailId = Mage::getStoreConfig("trans_email/ident_$adminEmailId/email");
  458. $toName = Mage::getStoreConfig("trans_email/ident_$adminEmailId/name");
  459.  
  460. if ($templateId) {
  461. $emailTemplate = Mage::getModel('core/email_template')->load($templateId);
  462. } else {
  463. $emailTemplate = Mage::getModel('core/email_template')
  464. ->loadDefault('marketplace_product_addproductapprovalemailnotificationtemplate');
  465. }
  466. $customer = Mage::getModel('customer/customer')->load($sellerId);
  467. $selleremail = $customer->getEmail();
  468. $recipient = $toMailId;
  469. $sellername = $customer->getName();
  470. $productname = $product->getName();
  471. $producturl = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $product->getId()));
  472.  
  473. $emailTemplate->setSenderName($sellername);
  474. $emailTemplate->setSenderEmail($selleremail);
  475. $emailTemplateVariables = (array('ownername' => $toName, 'sellername' => $sellername, 'selleremail' => $selleremail, 'productname' => $productname, 'producturl' => $producturl));
  476. $emailTemplate->setDesignConfig(array('area' => 'frontend'));
  477. $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
  478. $emailTemplate->send($recipient, $sellername, $emailTemplateVariables);
  479.  
  480.  
  481. }
  482. }
  483.  
  484. if ($type == 'configurable') {
  485. $this->_redirect('marketplace/product/configurable/', array('id' => $productId, 'set' => $set));
  486. return;
  487. }
  488.  
  489. $this->_redirect('marketplace/product/manage/');
  490. } catch (Mage_Core_Exception $e) {
  491. /**
  492. * Error message redirect to create new product page
  493. */
  494. Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
  495. $this->_redirect('marketplace/product/create/');
  496. } catch (Exception $e) {
  497. /**
  498. * Error message redirect to create new product page
  499. */
  500. Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
  501. $this->_redirect('marketplace/product/create/');
  502. }
  503. } else {
  504. Mage::getSingleton('core/session')->addError($this->__('Please enter all required fields'));
  505. if ($type == 'configurable') {
  506. $this->_redirect('marketplace/product/selectattributes/', array('set' => $set));
  507. return;
  508. }
  509. $this->_redirect('marketplace/product/new');
  510. }
  511. }
  512.  
  513. <catalog_product_save_after>
  514. <observers>
  515. <marketplace>
  516. <class>marketplace/observer</class>
  517. <method>sendme</method>
  518. </marketplace>
  519. </observers>
  520. </catalog_product_save_after>
  521.  
  522. public function sendme($observer)
  523. {
  524. $mail = Mage::getModel('core/email');
  525. $mail->setToName('User');
  526. $mail->setToEmail('testmail98@gmail.com');
  527. $mail->setBody('Send Test mail to you.....');
  528. $mail->setSubject('Test Mail');
  529. $mail->setFromEmail('testmail@gmail.com');
  530. $mail->setFromName("Send Test mail to you.....");
  531. $mail->setType('html');// YOu can use Html or text as Mail format
  532. $mail->send();
  533. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement