本文整理汇总了PHP中Magento\Framework\Registry类的典型用法代码示例。如果您正苦于以下问题:PHP Registry类的具体用法?PHP Registry怎么用?PHP Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Print Invoice Action
*
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
*/
public function execute()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$orderId = (int) $this->getRequest()->getParam('order_id');
$order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId);
}
if ($this->orderAuthorization->canView($order)) {
$this->_coreRegistry->register('current_order', $order);
if (isset($invoice)) {
$this->_coreRegistry->register('current_invoice', $invoice);
}
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->addHandle('print');
return $resultPage;
} else {
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
$resultRedirect->setPath('*/*/history');
} else {
$resultRedirect->setPath('sales/guest/form');
}
return $resultRedirect;
}
}
示例2: execute
/**
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()
{
$id = $this->getRequest()->getParam('id');
$model = $this->_objectManager->create('Magento\\Search\\Model\\Query');
if ($id) {
$model->load($id);
if (!$model->getId()) {
$this->messageManager->addError(__('This search no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('search/*');
return $resultRedirect;
}
}
// set entered data if was error when we do save
$data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getPageData(true);
if (!empty($data)) {
$model->addData($data);
}
$this->coreRegistry->register('current_catalog_search', $model);
$resultPage = $this->createPage();
$resultPage->getConfig()->getTitle()->prepend(__('Search Terms'));
$resultPage->getConfig()->getTitle()->prepend($id ? $model->getQueryText() : __('New Search'));
$resultPage->getLayout()->getBlock('adminhtml.search.term.edit')->setData('action', $this->getUrl('search/term/save'));
$resultPage->addBreadcrumb($id ? __('Edit Search') : __('New Search'), $id ? __('Edit Search') : __('New Search'));
return $resultPage;
}
示例3: execute
/**
* Print Invoice Action
*
* @return void
*/
public function execute()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$orderId = (int) $this->getRequest()->getParam('order_id');
$order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId);
}
if ($this->orderAuthorization->canView($order)) {
$this->_coreRegistry->register('current_order', $order);
if (isset($invoice)) {
$this->_coreRegistry->register('current_invoice', $invoice);
}
$this->_view->loadLayout('print');
$this->_view->renderLayout();
} else {
if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
$this->_redirect('*/*/history');
} else {
$this->_redirect('sales/guest/form');
}
}
}
示例4: getLog
/**
* Get log model
*
* @return \ClassyLlama\AvaTax\Model\Log
*/
public function getLog()
{
if (null === $this->currentLog) {
$this->currentLog = $this->coreRegistry->registry('current_log');
}
return $this->currentLog;
}
示例5: execute
/**
* @return void
*/
public function execute()
{
$ipId = $this->getRequest()->getParam('id');
/** @var \Rapidmage\Firewall\Model\Ip $model */
$model = $this->_ipFactory->create();
if ($ipId) {
$model->load($ipId);
if (!$model->getId()) {
$this->messageManager->addError(__('This Ip no longer exists.'));
$this->_redirect('*/*/');
return;
}
}
// Restore previously entered form data from session
$data = $this->_session->getIpData(true);
if (!empty($data)) {
$model->setData($data);
}
$this->_coreRegistry->register('firewall_blackip', $model);
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->_resultPageFactory->create();
$resultPage->setActiveMenu('Rapidmage_Firewall::main_menu');
$resultPage->getConfig()->getTitle()->prepend(__('Firewall'));
return $resultPage;
}
示例6: execute
public function execute()
{
// 1. Get ID and create model
$id = $this->getRequest()->getParam("cat_id");
$model = $this->_objectManager->create("OsmanSorkar\\Blog\\Model\\Category");
if ($id) {
$model->load($id);
if (!$model->getId()) {
$this->messageManager->addError(__("This Category no longer exists"));
/** \Magento\Backend\Model\View\Result\Redirct $resultRedirct */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
}
// 3. Set entered data if was error when we do save
$data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
if (!empty($data)) {
$model->setData($data);
}
// 4. Register model to use later in blocks
$this->_coreRegistry->register('blog_category', $model);
// 5. Build edit form
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Ashsmith_Blog::category');
$resultPage->addBreadcrumb(__('Blog Category Edit'), __('Blog Category Edit'));
$resultPage->addBreadcrumb(__('Manage Blog Category'), __('Manage Blog Category'));
$resultPage->getConfig()->getTitle()->prepend(__('Blog Category Edit'));
return $resultPage;
}
示例7: executeInternal
/**
* Action for reorder
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function executeInternal()
{
$result = $this->orderLoader->load($this->_request);
if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
return $result;
}
$order = $this->_coreRegistry->registry('current_order');
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
/* @var $cart \Magento\Checkout\Model\Cart */
$cart = $this->_objectManager->get('Magento\Checkout\Model\Cart');
$items = $order->getItemsCollection();
foreach ($items as $item) {
try {
$cart->addOrderItem($item);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
if ($this->_objectManager->get('Magento\Checkout\Model\Session')->getUseNotice(true)) {
$this->messageManager->addNotice($e->getMessage());
} else {
$this->messageManager->addError($e->getMessage());
}
return $resultRedirect->setPath('*/*/history');
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.'));
return $resultRedirect->setPath('checkout/cart');
}
}
$cart->save();
return $resultRedirect->setPath('checkout/cart');
}
示例8: execute
/**
* @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
*/
public function execute()
{
$articleId = (int) $this->getRequest()->getParam('id');
$article = $this->articleFactory->create();
$article->load($articleId);
if (!$article->isActive()) {
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('noroute');
return $resultForward;
}
$this->coreRegistry->register('current_article', $article);
$resultPage = $this->resultPageFactory->create();
$title = $article->getMetaTitle() ?: $article->getName();
$resultPage->getConfig()->getTitle()->set($title);
$resultPage->getConfig()->setDescription($article->getMetaDescription());
$resultPage->getConfig()->setKeywords($article->getMetaKeywords());
if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
/** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
$breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbsBlock) {
$breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'link' => $this->_url->getUrl('')]);
$breadcrumbsBlock->addCrumb('articles', ['label' => __('Articles'), 'link' => $this->urlModel->getListUrl()]);
$breadcrumbsBlock->addCrumb('article-' . $article->getId(), ['label' => $article->getName()]);
}
}
return $resultPage;
}
示例9: _beforeToHtml
/**
* Execute before toHtml() code.
*
* @return $this
*/
public function _beforeToHtml()
{
$this->_currency = $this->_currencyFactory->create()->load($this->_scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
$this->_collection = $this->_collectionFactory->create()->setCustomerIdFilter((int) $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))->setOrderStateFilter(Order::STATE_CANCELED, true)->load();
$this->_groupedCollection = [];
foreach ($this->_collection as $sale) {
if ($sale->getStoreId() !== null) {
$store = $this->_storeManager->getStore($sale->getStoreId());
$websiteId = $store->getWebsiteId();
$groupId = $store->getGroupId();
$storeId = $store->getId();
$sale->setWebsiteId($store->getWebsiteId());
$sale->setWebsiteName($store->getWebsite()->getName());
$sale->setGroupId($store->getGroupId());
$sale->setGroupName($store->getGroup()->getName());
} else {
$websiteId = 0;
$groupId = 0;
$storeId = 0;
$sale->setStoreName(__('Deleted Stores'));
}
$this->_groupedCollection[$websiteId][$groupId][$storeId] = $sale;
$this->_websiteCounts[$websiteId] = isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] + 1 : 1;
}
return parent::_beforeToHtml();
}
示例10: getHeaderText
/**
* Retrieve text for header element depending on loaded page
*
* @return string
*/
public function getHeaderText()
{
$process = $this->_coreRegistry->registry('current_index_process');
if ($process && $process->getId()) {
return __("'%1' Index Process Information", $process->getIndexer()->getName());
}
}
示例11: _toHtml
/**
* Forms script response
*
* @return string
*/
public function _toHtml()
{
$updateResult = $this->_coreRegistry->registry('composite_update_result');
$resultJson = $this->_jsonEncoder->encode($updateResult);
$jsVarname = $updateResult->getJsVarName();
return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
}
示例12: execute
/**
* Apply catalog price rules to product in admin
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$storeId = $product->getStoreId();
$date = $this->localeDate->scopeDate($storeId);
$key = false;
$ruleData = $this->coreRegistry->registry('rule_data');
if ($ruleData) {
$wId = $ruleData->getWebsiteId();
$gId = $ruleData->getCustomerGroupId();
$pId = $product->getId();
$key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
} elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) {
$wId = $product->getWebsiteId();
$gId = $product->getCustomerGroupId();
$pId = $product->getId();
$key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
}
if ($key) {
if (!$this->rulePricesStorage->hasRulePrice($key)) {
$rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
$this->rulePricesStorage->setRulePrice($key, $rulePrice);
}
if ($this->rulePricesStorage->getRulePrice($key) !== false) {
$finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
$product->setFinalPrice($finalPrice);
}
}
return $this;
}
示例13: getProduct
/**
* Get current product instance
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
if (!is_null($this->_product)) {
return $this->_product;
}
return $this->_coreRegistry->registry('product');
}
示例14: execute
/**
* Save order into registry to use it in the overloaded controller.
*
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{
/* @var $order \Magento\Sales\Model\Order */
$order = $observer->getEvent()->getData('order');
$this->_coreRegistry->register('hss_order', $order, true);
return $this;
}
示例15: _toHtml
/**
* @return string
*/
protected function _toHtml()
{
/** @var $rssObj \Magento\Rss\Model\Rss */
$rssObj = $this->_rssFactory->create();
$order = $this->_coreRegistry->registry('current_order');
if (!$order) {
return '';
}
$title = __('Order # %1 Notification(s)', $order->getIncrementId());
$newUrl = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
$rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
/** @var $resourceModel \Magento\Rss\Model\Resource\Order */
$resourceModel = $this->_orderFactory->create();
$results = $resourceModel->getAllCommentCollection($order->getId());
if ($results) {
foreach ($results as $result) {
$urlAppend = 'view';
$type = $result['entity_type_code'];
if ($type && $type != 'order') {
$urlAppend = $type;
}
$type = __(ucwords($type));
$title = __('Details for %1 #%2', $type, $result['increment_id']);
$description = '<p>' . __('Notified Date: %1<br/>', $this->formatDate($result['created_at'])) . __('Comment: %1<br/>', $result['comment']) . '</p>';
$url = $this->_urlBuilder->getUrl('sales/order/' . $urlAppend, array('order_id' => $order->getId()));
$rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
}
}
$title = __('Order #%1 created at %2', $order->getIncrementId(), $this->formatDate($order->getCreatedAt()));
$url = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
$description = '<p>' . __('Current Status: %1<br/>', $order->getStatusLabel()) . __('Total: %1<br/>', $order->formatPrice($order->getGrandTotal())) . '</p>';
$rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
return $rssObj->createRssXml();
}