PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/local/Ced/CsMarketplace/controllers/VebayController.php

https://gitlab.com/vincent.perdereau/picandparts
PHP | 102 lines | 66 code | 13 blank | 23 comment | 8 complexity | 81e094c4fcf5ff315c11493ba2c30f76 MD5 | raw file
  1. <?php
  2. /**
  3. * CedCommerce
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. *
  12. * @category Ced;
  13. * @package Ced_CsMarketplace
  14. * @author CedCommerce Core Team <coreteam@cedcommerce.com>
  15. * @copyright Copyright CedCommerce (http://cedcommerce.com/)
  16. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. */
  18. class Ced_CsMarketplace_VebayController extends Ced_CsMarketplace_Controller_AbstractController {
  19. public function indexAction() {
  20. if(!$this->_getSession()->getVendorId()) return;
  21. $this->loadLayout ();
  22. $this->_initLayoutMessages ( 'customer/session' );
  23. $this->_initLayoutMessages ( 'catalog/session' );
  24. $this->getLayout ()->getBlock ( 'head' )->setTitle ( $this->__ ( 'Ebay Import' ) );
  25. $navigationBlock = $this->getLayout()->getBlock('csmarketplace_vendor_navigation');
  26. if ($navigationBlock) {
  27. $navigationBlock->setActive('csmarketplace/vebay/index');
  28. }
  29. $this->renderLayout ();
  30. }
  31. public function saveAction() {
  32. if(!$this->_getSession()->getVendorId()) return;
  33. $this->loadLayout ();
  34. $this->_initLayoutMessages ( 'customer/session' );
  35. $this->_initLayoutMessages ( 'catalog/session' );
  36. $this->getLayout ()->getBlock ( 'head' )->setTitle ( $this->__ ( 'Ebay Import' ) );
  37. $navigationBlock = $this->getLayout()->getBlock('csmarketplace_vendor_navigation');
  38. if ($navigationBlock) {
  39. $navigationBlock->setActive('csmarketplace/vebay/index');
  40. }
  41. $from = strtotime($_REQUEST['DateFrom']);
  42. $to = strtotime($_REQUEST['DateTo']);
  43. $diff = floor(($to - $from)/ (60 * 60 * 24));
  44. if ($diff > 121) {
  45. $this->_getSession()->setErrorMessage(true);
  46. Mage::getSingleton('core/session')->addError('The time range between time from and time to has excedeed 121 days');
  47. //$this->_redirect('*/*/index');
  48. //return;
  49. }
  50. $this->renderLayout ();
  51. }
  52. public function requestPostAction() {
  53. $params = $this->getRequest()->getParams();
  54. $collection = Mage::getSingleton('core/session')->getData('ebay_api_response');
  55. $helper = Mage::helper('csmarketplace/vebay');
  56. if ($itemsIds = $params['itemids']) {
  57. foreach (explode(",", $itemsIds) as $itemId) {
  58. if (isset($collection[$itemId])) {
  59. $product = $helper->importItem($collection[$itemId]);
  60. $productData = array();
  61. $productData['product'] = array();
  62. $productData['product']['name'] = $product->getName()?$product->getName():'';
  63. $productData['product']['description'] = $product->getData('description')?$product->getData('description'):'';
  64. $productData['product']['short_description'] = $product->getData('short_description')?$product->getData('short_description'):'';
  65. $productData['product']['sku'] = $product->getSku();
  66. $productData['product']['weight'] = $product->getWeight();
  67. $productData['product']['stock_data']['qty'] = 1;
  68. $productData['product']['stock_data']['is_in_stock'] = 1;
  69. $productData['product']['stock_data']['price'] = 1;
  70. $productData['product']['stock_data']['special_price'] = 1;
  71. Mage::getModel('csmarketplace/vproducts')->processPostSave('new',$product,$productData);
  72. //Mage::getModel('csmarketplace/vproducts')->setStoreId($product->getStoreId())->setProductData($product)->saveProduct($this->mode);
  73. }
  74. }
  75. /* $this->loadLayout ();
  76. $this->_initLayoutMessages ( 'customer/session' );
  77. $this->_initLayoutMessages ( 'catalog/session' );
  78. $this->renderLayout ();*/
  79. $result = array();
  80. $result['content'] = 'super';
  81. $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);
  82. $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
  83. } else {
  84. $this->_getSession()->addError('No selected items');
  85. $this->_redirect('*/*/index');
  86. return;
  87. }
  88. }
  89. }