当前位置: 首页>>代码示例>>PHP>>正文


PHP Data::jsonEncode方法代码示例

本文整理汇总了PHP中Magento\Framework\Json\Helper\Data::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::jsonEncode方法的具体用法?PHP Data::jsonEncode怎么用?PHP Data::jsonEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Json\Helper\Data的用法示例。


在下文中一共展示了Data::jsonEncode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testJsonEncode

 public function testJsonEncode()
 {
     $expected = '"valueToEncode"';
     $valueToEncode = 'valueToEncode';
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($expected);
     $this->assertEquals($expected, $this->helper->jsonEncode($valueToEncode));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:7,代码来源:DataTest.php

示例2: testJsonEncodeDecode

 public function testJsonEncodeDecode()
 {
     $data = ['one' => 1, 'two' => 'two'];
     $jsonData = '{"one":1,"two":"two"}';
     $this->assertEquals($jsonData, $this->_helper->jsonEncode($data));
     $this->assertEquals($data, $this->_helper->jsonDecode($jsonData));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:7,代码来源:DataTest.php

示例3: _redirect

 /**
  * Don't actually redirect if we've got AJAX request - return redirect URL instead.
  *
  * @param string $path
  * @param array $arguments
  * @return $this|\Magento\Backend\App\AbstractAction
  */
 protected function _redirect($path, $arguments = [])
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->representJson($this->jsonHelper->jsonEncode(['_redirect' => $this->getUrl($path, $arguments)]));
         return $this;
     } else {
         return parent::_redirect($path, $arguments);
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:Integration.php

示例4: jsonResponse

 /**
  * Compile JSON response
  *
  * @param string $error
  * @return Http
  */
 protected function jsonResponse($error = '')
 {
     $response = $this->sidebar->getResponseData($error);
     if (empty($error)) {
         $resultPage = $this->resultPageFactory->create();
         $block = $resultPage->getLayout()->getBlock('minicart.content')->toHtml();
         $response['content'] = $block;
     }
     return $this->getResponse()->representJson($this->jsonHelper->jsonEncode($response));
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:RemoveItem.php

示例5: executeInternal

 /**
  * Search for attributes by part of attribute's label in admin store
  *
  * @return void
  */
 public function executeInternal()
 {
     $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
     $collection = $this->collectionFactory->create();
     $collection->addFieldToFilter('main_table.attribute_id', $this->getRequest()->getParam('attributes'));
     $attributes = [];
     foreach ($collection->getItems() as $attribute) {
         $attributes[] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
     }
     $this->getResponse()->representJson($this->jsonHelper->jsonEncode($attributes));
 }
开发者ID:nblair,项目名称:magescotch,代码行数:16,代码来源:GetAttributes.php

示例6: execute

 /**
  * @return void
  */
 public function execute()
 {
     $severity = $this->getRequest()->getParam('severity');
     if ($severity) {
         $this->messageCollection->setSeverity($severity);
     }
     $result = [];
     foreach ($this->messageCollection->getItems() as $item) {
         $result[] = ['severity' => $item->getSeverity(), 'text' => $item->getText()];
     }
     if (empty($result)) {
         $result[] = ['severity' => (string) \Magento\Framework\Notification\MessageInterface::SEVERITY_NOTICE, 'text' => 'You have viewed and resolved all recent system notices. ' . 'Please refresh the web page to clear the notice alert.'];
     }
     $this->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:ListAction.php

示例7: execute

 /**
  * Check Captcha On Checkout as Guest Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'guest_checkout';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $checkoutMethod = $this->_typeOnepage->getQuote()->getCheckoutMethod();
     if ($checkoutMethod == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
         if ($captchaModel->isRequired()) {
             $controller = $observer->getControllerAction();
             if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
                 $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $result = ['error' => 1, 'message' => __('Incorrect CAPTCHA')];
                 $controller->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
             }
         }
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:23,代码来源:CheckGuestCheckoutObserver.php

示例8: getJsonConfigurableAttributes

 /**
  * Get JSON string that contains attribute code and value
  *
  * @param array $options
  * @return string
  */
 protected function getJsonConfigurableAttributes(array $options = [])
 {
     $result = [];
     foreach ($options as $option) {
         $result[$option['attribute_code']] = $option['value'];
     }
     return $this->jsonHelper->jsonEncode($result);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:AssociatedProducts.php

示例9: getCountriesWithStatesRequired

 /**
  * Returns the list of countries, for which region is required
  *
  * @param boolean $asJson
  * @return array
  */
 public function getCountriesWithStatesRequired($asJson = false)
 {
     $value = trim($this->scopeConfig->getValue(self::XML_PATH_STATES_REQUIRED, ScopeInterface::SCOPE_STORE));
     $countryList = preg_split('/\\,/', $value, 0, PREG_SPLIT_NO_EMPTY);
     if ($asJson) {
         return $this->jsonHelper->jsonEncode($countryList);
     }
     return $countryList;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Data.php

示例10: getAllRatesByProductClassJson

 /**
  * Get all tax rates JSON for all product tax classes.
  *
  * @return string
  */
 public function getAllRatesByProductClassJson()
 {
     $result = [];
     foreach ($this->productTaxClassSource->getAllOptions() as $productTaxClass) {
         $taxClassId = $productTaxClass['value'];
         $taxRate = $this->calculationService->getDefaultCalculatedRate($taxClassId, $this->currentCustomer->getCustomerId(), $this->getStore()->getId());
         $result["value_{$taxClassId}"] = $taxRate;
     }
     return $this->jsonHelper->jsonEncode($result);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Js.php

示例11: getPriceFormat

 /**
  * Get prices javascript format json
  *
  * @param  null|int|string|Store $store
  * @return string
  */
 public function getPriceFormat($store = null)
 {
     $this->_localeResolver->emulate($store);
     $priceFormat = $this->_localeFormat->getPriceFormat();
     $this->_localeResolver->revert();
     if ($store) {
         $priceFormat['pattern'] = $this->_storeManager->getStore($store)->getCurrentCurrency()->getOutputFormat();
     }
     return $this->jsonHelper->jsonEncode($priceFormat);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Data.php

示例12: getUsedDefaultForPaths

 /**
  * Get paths of where current template is used as default
  *
  * @param bool $asJSON
  * @return string
  */
 public function getUsedDefaultForPaths($asJSON = true)
 {
     /** @var $template \Magento\Email\Model\BackendTemplate */
     $template = $this->getEmailTemplate();
     $paths = $template->getSystemConfigPathsWhereUsedAsDefault();
     $pathsParts = $this->_getSystemConfigPathsParts($paths);
     if ($asJSON) {
         return $this->jsonHelper->jsonEncode($pathsParts);
     }
     return $pathsParts;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Edit.php

示例13: execute

 /**
  * Validate api user.
  */
 public function execute()
 {
     $params = $this->getRequest()->getParams();
     $apiUsername = $params['api_username'];
     //@codingStandardsIgnoreStart
     $apiPassword = base64_decode($params['api_password']);
     //@codingStandardsIgnoreEnd
     //validate api, check against account info.
     if ($this->data->isEnabled()) {
         $client = $this->data->getWebsiteApiClient();
         $result = $client->validate($apiUsername, $apiPassword);
         $resonseData['success'] = true;
         //validation failed
         if (!$result) {
             $resonseData['success'] = false;
             $resonseData['message'] = 'Authorization has been denied for this request.';
         }
         $this->getResponse()->representJson($this->jsonHelper->jsonEncode($resonseData));
     }
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:23,代码来源:Ajaxvalidation.php

示例14: build

 /**
  * Duplicating downloadable product data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Product $duplicate
  * @return void
  */
 public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
 {
     if ($product->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         //do nothing if not downloadable
         return;
     }
     $data = [];
     /** @var \Magento\Downloadable\Model\Product\Type $type */
     $type = $product->getTypeInstance();
     foreach ($type->getLinks($product) as $link) {
         /* @var \Magento\Downloadable\Model\Link $link */
         $linkData = $link->getData();
         $data['link'][] = ['is_delete' => false, 'link_id' => null, 'title' => $linkData['title'], 'is_shareable' => $linkData['is_shareable'], 'sample' => ['type' => $linkData['sample_type'], 'url' => $linkData['sample_url'], 'file' => $this->jsonHelper->jsonEncode([['file' => $linkData['sample_file'], 'name' => $linkData['sample_file'], 'size' => 0, 'status' => null]])], 'file' => $this->jsonHelper->jsonEncode([['file' => $linkData['link_file'], 'name' => $linkData['link_file'], 'size' => 0, 'status' => null]]), 'type' => $linkData['link_type'], 'link_url' => $linkData['link_url'], 'sort_order' => $linkData['sort_order'], 'number_of_downloads' => $linkData['number_of_downloads'], 'price' => $linkData['price']];
     }
     /** @var \Magento\Downloadable\Model\Sample $sample */
     foreach ($type->getSamples($product) as $sample) {
         $sampleData = $sample->getData();
         $data['sample'][] = ['is_delete' => false, 'sample_id' => null, 'title' => $sampleData['title'], 'type' => $sampleData['sample_type'], 'file' => $this->jsonHelper->jsonEncode([['file' => $sampleData['sample_file'], 'name' => $sampleData['sample_file'], 'size' => 0, 'status' => null]]), 'sample_url' => $sampleData['sample_url'], 'sort_order' => $sampleData['sort_order']];
     }
     $duplicate->setDownloadableData($data);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:28,代码来源:Downloadable.php

示例15: getCookiesMessages

 /**
  * Return messages stored in cookies
  *
  * @return array
  */
 protected function getCookiesMessages()
 {
     try {
         $messages = $this->jsonHelper->jsonDecode($this->cookieManager->getCookie(self::MESSAGES_COOKIES_NAME, $this->jsonHelper->jsonEncode([])));
         if (!is_array($messages)) {
             $messages = [];
         }
     } catch (\Zend_Json_Exception $e) {
         $messages = [];
     }
     return $messages;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:MessagePlugin.php


注:本文中的Magento\Framework\Json\Helper\Data::jsonEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。