/**
  * save product data
  *
  * @param $observer
  *
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $downloads = $this->context->getRequest()->getFiles('downloads', -1);
     if ($downloads != '-1') {
         // Get current product
         $product = $this->coreRegistry->registry('product');
         $productId = $product->getId();
         // Loop through uploaded downlaods
         foreach ($downloads as $download) {
             // Upload file
             $uploadedDownload = $this->upload->uploadFile($download);
             if ($uploadedDownload) {
                 $objectManager = $this->context->getObjectManager();
                 // Store date in database
                 $download = $objectManager->create('Sebwite\\ProductDownloads\\Model\\Download');
                 $download->setDownloadUrl($uploadedDownload['file']);
                 $download->setDownloadFile($uploadedDownload['name']);
                 $download->setDownloadType($uploadedDownload['type']);
                 $download->setProductId($productId);
                 $download->save();
             }
         }
     }
     return $this;
 }
 /**
  * ApiValidate constructor.
  *
  * @param \Dotdigitalgroup\Email\Helper\Data           $data
  * @param \Magento\Backend\App\Action\Context          $context
  * @param \Magento\Framework\App\Config\Storage\Writer $writer
  */
 public function __construct(\Dotdigitalgroup\Email\Helper\Data $data, \Dotdigitalgroup\Email\Model\Apiconnector\Test $test, \Magento\Backend\App\Action\Context $context, \Magento\Framework\App\Config\Storage\Writer $writer)
 {
     $this->helper = $data;
     $this->test = $test;
     $this->context = $context;
     $this->messageManager = $context->getMessageManager();
     $this->objectManager = $context->getObjectManager();
     $this->writer = $writer;
 }
Ejemplo n.º 3
0
 /**
  * ApiValidate constructor.
  *
  * @param \Dotdigitalgroup\Email\Model\ContactFactory  $contactFactory
  * @param \Dotdigitalgroup\Email\Helper\Data           $data
  * @param \Magento\Backend\App\Action\Context          $context
  * @param \Magento\Store\Model\StoreManagerInterface   $storeManagerInterface
  * @param \Magento\Framework\App\Config\Storage\Writer $writer
  */
 public function __construct(\Dotdigitalgroup\Email\Model\ContactFactory $contactFactory, \Dotdigitalgroup\Email\Helper\Data $data, \Magento\Backend\App\Action\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, \Magento\Framework\App\Config\Storage\Writer $writer)
 {
     $this->_helper = $data;
     $this->_context = $context;
     $this->_contactFactory = $contactFactory;
     $this->_request = $context->getRequest();
     $this->_storeManager = $storeManagerInterface;
     $this->messageManager = $context->getMessageManager();
     $this->_objectManager = $context->getObjectManager();
     $this->_writer = $writer;
 }