本文整理汇总了PHP中Magento\Framework\App\State::emulateAreaCode方法的典型用法代码示例。如果您正苦于以下问题:PHP State::emulateAreaCode方法的具体用法?PHP State::emulateAreaCode怎么用?PHP State::emulateAreaCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\State
的用法示例。
在下文中一共展示了State::emulateAreaCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmulateAreaCodeException
/**
* @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: _beforeToHtml
/**
* 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: exec
/**
* 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: execute
/**
* 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: layoutDirective
/**
* 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: layoutDirective
/**
* 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();
}
}