本文整理汇总了PHP中Magento\Framework\Registry::registry方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::registry方法的具体用法?PHP Registry::registry怎么用?PHP Registry::registry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Registry
的用法示例。
在下文中一共展示了Registry::registry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterGenerateXml
/**
* After generate Xml
*
* @param \Magento\Framework\View\LayoutInterface $subject
* @param \Magento\Framework\View\LayoutInterface $result
* @return \Magento\Framework\View\LayoutInterface
*/
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
{
if (!$this->registry->registry(self::REGISTRY_KEY)) {
$this->registry->register(self::REGISTRY_KEY, $this->customerSession->getCustomer());
}
return $result;
}
示例2: toOptionArray
/**
* @return array
*/
public function toOptionArray()
{
$fields = [];
$fields[] = ['value' => '0', 'label' => '-- Please Select --'];
$apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
if ($apiEnabled) {
$savedCampaigns = $this->registry->registry('campaigns');
if (is_array($savedCampaigns)) {
$campaigns = $savedCampaigns;
} else {
//grab the datafields request and save to register
$client = $this->helper->getWebsiteApiClient();
$campaigns = $client->getCampaigns();
$this->registry->register('campaigns', $campaigns);
}
//set the api error message for the first option
if (isset($campaigns->message)) {
//message
$fields[] = ['value' => 0, 'label' => $campaigns->message];
} elseif (!empty($campaigns)) {
//loop for all campaing options
foreach ($campaigns as $campaign) {
if (isset($campaign->name)) {
//@codingStandardsIgnoreStart
$fields[] = ['value' => $campaign->id, 'label' => addslashes($campaign->name)];
//@codingStandardsIgnoreEnd
}
}
}
}
return $fields;
}
示例3: toOptionArray
/**
* Get options.
*
* @return array
*/
public function toOptionArray()
{
$fields = [];
$fields[] = ['value' => '0', 'label' => '-- Disabled --'];
$websiteName = $this->request->getParam('website', false);
$website = $websiteName ? $this->storeManager->getWebsite($websiteName) : 0;
if ($this->helper->isEnabled($website)) {
$savedPrograms = $this->registry->registry('programs');
//get saved datafileds from registry
if (is_array($savedPrograms)) {
$programs = $savedPrograms;
} else {
//grab the datafields request and save to register
$client = $this->helper->getWebsiteApiClient($website);
$programs = $client->getPrograms();
$this->registry->unregister('programs');
$this->registry->register('programs', $programs);
}
//set the api error message for the first option
if (isset($programs->message)) {
//message
$fields[] = ['value' => 0, 'label' => $programs->message];
} elseif (!empty($programs)) {
//loop for all programs option
foreach ($programs as $program) {
if (isset($program->id) && $program->status == 'Active') {
//@codingStandardsIgnoreStart
$fields[] = ['value' => $program->id, 'label' => addslashes($program->name)];
//@codingStandardsIgnoreEnd
}
}
}
}
return $fields;
}
示例4: _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();
}
示例5: 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;
}
示例6: execute
/**
* Execute method.
*
* @param \Magento\Framework\Event\Observer $observer
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
if (!$this->registry->registry('core_config_data_save_after_done')) {
if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
if (isset($groups['catalog_sync']['fields']['catalog_values']['value'])) {
$configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
$configBefore = $this->registry->registry('core_config_data_save_before');
if ($configAfter != $configBefore) {
//reset catalog to re-import
$this->connectorCatalogFactory->create()->reset();
}
$this->registry->register('core_config_data_save_after_done', true);
}
}
}
if (!$this->registry->registry('core_config_data_save_after_done_status')) {
if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
$configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
$configBefore = $this->registry->registry('core_config_data_save_before_status');
if ($configAfter != $configBefore) {
//reset all contacts
$this->connectorContactFactory->create()->resetAllContacts();
}
$this->registry->register('core_config_data_save_after_done_status', true);
}
}
}
} catch (\Exception $e) {
$this->helper->debug((string) $e, []);
}
return $this;
}
示例7: _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();
}
示例8: toOptionArray
/**
* Datafields option.
*
* @return array
*/
public function toOptionArray()
{
$fields = [];
//default data option
$fields[] = ['value' => '0', 'label' => '-- Please Select --'];
$apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
if ($apiEnabled) {
$savedDatafields = $this->registry->registry('datafields');
//get saved datafileds from registry
if ($savedDatafields) {
$datafields = $savedDatafields;
} else {
//grab the datafields request and save to register
$client = $this->helper->getWebsiteApiClient();
$datafields = $client->getDatafields();
$this->registry->register('datafields', $datafields);
}
//set the api error message for the first option
if (isset($datafields->message)) {
//message
$fields[] = ['value' => 0, 'label' => $datafields->message];
} else {
//loop for all datafields option
foreach ($datafields as $datafield) {
if (isset($datafield->name)) {
$fields[] = ['value' => $datafield->name, 'label' => $datafield->name];
}
}
}
}
return $fields;
}
示例9: execute
/**
* Save order into registry to use it in the overloaded controller.
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/* @var $order Order */
$order = $this->coreRegistry->registry('directpost_order');
if (!$order || !$order->getId()) {
return $this;
}
$payment = $order->getPayment();
if (!$payment || $payment->getMethod() != $this->payment->getCode()) {
return $this;
}
$result = $observer->getData('result')->getData();
if (!empty($result['error'])) {
return $this;
}
// if success, then set order to session and add new fields
$this->session->addCheckoutOrderIncrementId($order->getIncrementId());
$this->session->setLastOrderIncrementId($order->getIncrementId());
$requestToAuthorizenet = $payment->getMethodInstance()->generateRequestFromOrder($order);
$requestToAuthorizenet->setControllerActionName($observer->getData('action')->getRequest()->getControllerName());
$requestToAuthorizenet->setIsSecure((string) $this->storeManager->getStore()->isCurrentlySecure());
$result[$this->payment->getCode()] = ['fields' => $requestToAuthorizenet->getData()];
$observer->getData('result')->setData($result);
return $this;
}
示例10: toOptionArray
/**
* Retrieve list of options.
*
* @return array
*/
public function toOptionArray()
{
$fields = [];
// Add a "Do Not Map" Option
$fields[] = ['value' => 0, 'label' => '-- Please Select --'];
$apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
if ($apiEnabled) {
$savedAddressbooks = $this->registry->registry('addressbooks');
if ($savedAddressbooks) {
$addressBooks = $savedAddressbooks;
} else {
$client = $this->helper->getWebsiteApiClient();
//make an api call an register the addressbooks
$addressBooks = $client->getAddressBooks();
if ($addressBooks) {
$this->registry->register('addressbooks', $addressBooks);
}
}
//set up fields with book id and label
foreach ($addressBooks as $book) {
if (isset($book->id)) {
$fields[] = ['value' => (string) $book->id, 'label' => (string) $book->name];
}
}
}
return $fields;
}
示例11: _prepareLayout
/**
* {@inheritdoc}
*/
protected function _prepareLayout()
{
$this->setId('customerViewAccordion');
$this->addItem('lastOrders', array('title' => __('Recent Orders'), 'ajax' => true, 'content_url' => $this->getUrl('customer/*/lastOrders', array('_current' => true))));
$customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
$customer = $this->getCustomer($customerId);
$websiteIds = $this->_shareConfig->getSharedWebsiteIds($customer->getWebsiteId());
// add shopping cart block of each website
foreach ($websiteIds as $websiteId) {
$website = $this->_storeManager->getWebsite($websiteId);
// count cart items
$cartItemsCount = $this->_quoteFactory->create()->setWebsite($website)->loadByCustomer($customerId)->getItemsCollection(false)->addFieldToFilter('parent_item_id', array('null' => true))->getSize();
// prepare title for cart
$title = __('Shopping Cart - %1 item(s)', $cartItemsCount);
if (count($websiteIds) > 1) {
$title = __('Shopping Cart of %1 - %2 item(s)', $website->getName(), $cartItemsCount);
}
// add cart ajax accordion
$this->addItem('shopingCart' . $websiteId, array('title' => $title, 'ajax' => true, 'content_url' => $this->getUrl('customer/*/viewCart', array('_current' => true, 'website_id' => $websiteId))));
}
// count wishlist items
$wishlistCount = $this->_itemsFactory->create()->addCustomerIdFilter($customerId)->addStoreData()->getSize();
// add wishlist ajax accordion
$this->addItem('wishlist', array('title' => __('Wishlist - %1 item(s)', $wishlistCount), 'ajax' => true, 'content_url' => $this->getUrl('customer/*/viewWishlist', array('_current' => true))));
}
示例12: _prepareForm
/**
* {@inheritdoc}
*/
protected function _prepareForm()
{
/** @var \Mirasvit\Search\Model\Index $model */
$model = $this->registry->registry('current_model');
$form = $this->formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('General Information'), 'class' => 'fieldset-wide']);
if ($model->getId()) {
$fieldset->addField('index_id', 'hidden', ['name' => 'id']);
}
$fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Title'), 'required' => true]);
if ($model->getId()) {
$model->setData('index_label', $model->getIndexInstance()->toString());
$fieldset->addField('index_label', 'label', ['label' => __('Index')]);
} else {
$fieldset->addField('code', 'select', ['label' => __('Index'), 'name' => 'code', 'required' => true, 'values' => $this->sourceIndex->toOptionArray(true)]);
}
$fieldset->addField('position', 'text', ['name' => 'position', 'label' => __('Position'), 'required' => true]);
$fieldset->addField('is_active', 'select', ['label' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => ['1' => __('Enabled'), '0' => __('Disabled')]]);
if (!$model->getId()) {
$model->setData('is_active', '1');
}
$form->setValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}
示例13: getProduct
/**
* Retrieve currently viewed product object
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
if (!$this->hasData('product')) {
$this->setData('product', $this->_coreRegistry->registry('product'));
}
return $this->getData('product');
}
示例14: execute
/**
* If it's configured to capture on shipment - do this.
*
* @param \Magento\Framework\Event\Observer $observer
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$email = $customer->getEmail();
$websiteId = $customer->getWebsiteId();
$customerId = $customer->getEntityId();
$isSubscribed = $customer->getIsSubscribed();
try {
// fix for a multiple hit of the observer
$emailReg = $this->registry->registry($email . '_customer_save');
if ($emailReg) {
return $this;
}
$this->registry->register($email . '_customer_save', $email);
$emailBefore = $this->customerFactory->create()->load($customer->getId())->getEmail();
$contactModel = $this->contactFactory->create()->loadByCustomerEmail($emailBefore, $websiteId);
//email change detection
if ($email != $emailBefore) {
$this->helper->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
$data = ['emailBefore' => $emailBefore, 'email' => $email, 'isSubscribed' => $isSubscribed];
$this->importerFactory->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT_UPDATE, $data, \Dotdigitalgroup\Email\Model\Importer::MODE_CONTACT_EMAIL_UPDATE, $websiteId);
} elseif (!$emailBefore) {
//for new contacts update email
$contactModel->setEmail($email);
}
$contactModel->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED)->setCustomerId($customerId)->save();
} catch (\Exception $e) {
$this->helper->debug((string) $e, []);
}
return $this;
}
示例15: 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;
}