예제 #1
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Some error
  */
 public function testEmulateAreaCodeException()
 {
     $areaCode = 'original code';
     $emulatedCode = 'emulated code';
     $this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode);
     $this->model->setAreaCode($areaCode);
     $this->model->emulateAreaCode($emulatedCode, [$this, 'emulateAreaCodeCallbackException']);
     $this->assertEquals($this->model->getAreaCode(), $areaCode);
 }
예제 #2
0
 /**
  * Add necessary options
  *
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     if (!$this->getOptions()) {
         $this->addOption('', __('-- Please Select --'));
         $layoutUpdateParams = array('theme' => $this->_getThemeInstance($this->getTheme()));
         $designAbstractions = $this->_appState->emulateAreaCode('frontend', array($this->_getLayoutProcessor($layoutUpdateParams), 'getAllDesignAbstractions'));
         $this->_addDesignAbstractionOptions($designAbstractions);
     }
     return parent::_beforeToHtml();
 }
예제 #3
0
 /**
  * Execute SampleData module installation.
  * Catch exception if it appeared and continue installation
  *
  * @param InstallerInterface $installer
  * @return void
  */
 public function exec(InstallerInterface $installer)
 {
     try {
         $this->appState->emulateAreaCode('setup', [$installer, 'install']);
         $this->state->setInstalled();
     } catch (\Exception $e) {
         $this->state->setError();
         $this->logger->error('Sample Data error: ' . $e->getMessage());
     }
 }
예제 #4
0
 /**
  * Main method ran during event raise
  *
  * @param \Magento\Framework\Event\Observer $observer
  */
 public function execute(Observer $observer)
 {
     if (!$this->canRun()) {
         return false;
     }
     $order = $observer->getOrder();
     if (!$order || !$order->getId()) {
         return false;
     }
     $this->logger->addInfo("Auto-invoicing  order " . $order->getId());
     if (!$order->canInvoice() || $order->getState() != \Magento\Sales\Model\Order::STATE_PROCESSING) {
         $this->logger->addInfo("Order cannot be invoiced");
         if ($this->apiConfig->isLoggingEnabled()) {
             $this->apiOrderLogger->logInvoice($order);
         }
         return false;
     }
     $invoice = $this->state->emulateAreaCode('adminhtml', array($this->invoiceService, 'prepareInvoice'), array($order));
     if (!$invoice->getTotalQty()) {
         $this->logger->addInfo("Cannot create an invoice without products");
         return;
     }
     try {
         $invoice->setRequestedCaptureCase($this->apiConfig->getCaptureCase())->addComment(__('Invoice automatically created by Riskified when order was approved'), false, false)->register();
         $order->setStatus('riskified_approved');
         $order->addStatusHistoryComment(__("Reviewed and approved by Riskified"), 'riskified_approved');
         $order->save();
     } catch (\Exception $e) {
         $this->logger->addInfo("Error creating invoice: " . $e->getMessage());
         return false;
     }
     try {
         $invoice->save();
         $invoice->getOrder()->save();
     } catch (\Exception $e) {
         $this->logger->addCritical("Error creating transaction: " . $e->getMessage());
         return false;
     }
     $this->logger->addInfo("Transaction saved");
 }
예제 #5
0
 /**
  * Retrieve layout html directive
  *
  * @param string[] $construction
  * @return string
  */
 public function layoutDirective($construction)
 {
     $this->_directiveParams = $this->_getParameters($construction[2]);
     if (!isset($this->_directiveParams['area'])) {
         $this->_directiveParams['area'] = 'frontend';
     }
     if ($this->_directiveParams['area'] != $this->_appState->getAreaCode()) {
         return $this->_appState->emulateAreaCode($this->_directiveParams['area'], [$this, 'emulateAreaCallback']);
     } else {
         return $this->emulateAreaCallback();
     }
 }
예제 #6
0
 /**
  * Retrieve layout html directive
  *
  * @param string[] $construction
  * @return string
  */
 public function layoutDirective($construction)
 {
     $this->_directiveParams = $this->getParameters($construction[2]);
     if (!isset($this->_directiveParams['area'])) {
         $this->_directiveParams['area'] = \Magento\Framework\App\Area::AREA_FRONTEND;
     }
     if ($this->_directiveParams['area'] != $this->_appState->getAreaCode()) {
         return $this->_appState->emulateAreaCode($this->_directiveParams['area'], [$this, 'emulateAreaCallback']);
     } else {
         return $this->emulateAreaCallback();
     }
 }