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


PHP Data::jsonDecode方法代码示例

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


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

示例1: 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

示例2: testJsonDecode

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

示例3: execute

 /**
  * Login registered users and initiate a session.
  *
  * Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $credentials = null;
     $httpBadRequestCode = 400;
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $credentials = $this->helper->jsonDecode($this->getRequest()->getContent());
     } catch (\Exception $e) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     $response = ['errors' => false, 'message' => __('Login successful.')];
     try {
         $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']);
         $this->customerSession->setCustomerDataAsLoggedIn($customer);
         $this->customerSession->regenerateId();
     } catch (EmailNotConfirmedException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (InvalidEmailOrPasswordException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['errors' => true, 'message' => __('Something went wrong while validating the login and password.')];
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($response);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:37,代码来源:Login.php

示例4: execute

 public function execute()
 {
     if ($this->_expireAjax()) {
         return;
     }
     $data = $this->_jsonHelper->jsonDecode($this->getRequest()->getContent());
     if (!empty($data['vatpername']) && !empty($data['vatcomment'])) {
         $data['vatdeclare'] = 1;
     }
     $vatExemptModel = $this->_vatExemptModel;
     $result = $vatExemptModel->saveVatexempt($data);
     return $this->resultJsonFactory->create()->setData($result);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:AdminSaveVatexempt.php

示例5: _validateProductVariations

 /**
  * Product variations attributes validation
  *
  * @param Product $parentProduct
  * @param array $products
  * @param RequestInterface $request
  * @return array
  */
 protected function _validateProductVariations(Product $parentProduct, array $products, RequestInterface $request)
 {
     $this->eventManager->dispatch('catalog_product_validate_variations_before', ['product' => $parentProduct, 'variations' => $products]);
     $validationResult = [];
     foreach ($products as $productData) {
         $product = $this->productFactory->create();
         $product->setData('_edit_mode', true);
         $storeId = $request->getParam('store');
         if ($storeId) {
             $product->setStoreId($storeId);
         }
         $product->setAttributeSetId($parentProduct->getAttributeSetId());
         $product->addData($this->getRequiredDataFromProduct($parentProduct));
         $product->addData($productData);
         $product->setCollectExceptionMessages(true);
         $configurableAttribute = [];
         $encodedData = $productData['configurable_attribute'];
         if ($encodedData) {
             $configurableAttribute = $this->jsonHelper->jsonDecode($encodedData);
         }
         $configurableAttribute = implode('-', $configurableAttribute);
         $errorAttributes = $product->validate();
         if (is_array($errorAttributes)) {
             foreach ($errorAttributes as $attributeCode => $result) {
                 if (is_string($result)) {
                     $key = 'variations-matrix-' . $configurableAttribute . '-' . $attributeCode;
                     $validationResult[$key] = $result;
                 }
             }
         }
     }
     return $validationResult;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:41,代码来源:Plugin.php

示例6: beforeSave

 /**
  * @param \Magento\Framework\Object $object
  * @return $this|void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function beforeSave($object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     $value = $object->getData($attrCode);
     if (!is_array($value) || !isset($value['images'])) {
         return;
     }
     if (!is_array($value['images']) && strlen($value['images']) > 0) {
         $value['images'] = $this->jsonHelper->jsonDecode($value['images']);
     }
     if (!is_array($value['images'])) {
         $value['images'] = [];
     }
     $clearImages = [];
     $newImages = [];
     $existImages = [];
     if ($object->getIsDuplicate() != true) {
         foreach ($value['images'] as &$image) {
             if (!empty($image['removed'])) {
                 $clearImages[] = $image['file'];
             } elseif (empty($image['value_id'])) {
                 $newFile = $this->_moveImageFromTmp($image['file']);
                 $image['new_file'] = $newFile;
                 $newImages[$image['file']] = $image;
                 $this->_renamedImages[$image['file']] = $newFile;
                 $image['file'] = $newFile;
             } else {
                 $existImages[$image['file']] = $image;
             }
         }
     } else {
         // For duplicating we need copy original images.
         $duplicate = [];
         foreach ($value['images'] as &$image) {
             if (empty($image['value_id'])) {
                 continue;
             }
             $duplicate[$image['value_id']] = $this->_copyImage($image['file']);
             $image['new_file'] = $duplicate[$image['value_id']];
             $newImages[$image['file']] = $image;
         }
         $value['duplicate'] = $duplicate;
     }
     foreach ($object->getMediaAttributes() as $mediaAttribute) {
         $mediaAttrCode = $mediaAttribute->getAttributeCode();
         $attrData = $object->getData($mediaAttrCode);
         if (in_array($attrData, $clearImages)) {
             $object->setData($mediaAttrCode, 'no_selection');
         }
         if (in_array($attrData, array_keys($newImages))) {
             $object->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
             $object->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
         }
         if (in_array($attrData, array_keys($existImages))) {
             $object->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
         }
     }
     $object->setData($attrCode, $value);
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:66,代码来源:Media.php

示例7: execute

 /**
  * Login registered users and initiate a session.
  *
  * Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
  *
  * @return \Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     $credentials = null;
     $httpBadRequestCode = 400;
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $credentials = $this->helper->jsonDecode($this->getRequest()->getContent());
     } catch (\Exception $e) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     $response = ['errors' => false, 'message' => __('Login successful.')];
     try {
         $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']);
         $this->customerSession->setCustomerDataAsLoggedIn($customer);
         $this->customerSession->regenerateId();
         $redirectRoute = $this->getAccountRedirect()->getRedirectCookie();
         if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) {
             $response['redirectUrl'] = $this->_redirect->success($redirectRoute);
             $this->getAccountRedirect()->clearRedirectCookie();
         }
     } catch (EmailNotConfirmedException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (InvalidEmailOrPasswordException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['errors' => true, 'message' => __('Invalid login or password.')];
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($response);
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:43,代码来源:Login.php

示例8: setFiles

 /**
  * Load file and set path to sample
  *
  * @param SampleInterface $sample
  * @return void
  */
 protected function setFiles(SampleInterface $sample)
 {
     if ($sample->getSampleType() == \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE && $sample->getFile()) {
         $sampleFileName = $this->downloadableFile->moveFileFromTmp($sample->getBaseTmpPath(), $sample->getBasePath(), $this->jsonHelper->jsonDecode($sample->getFile()));
         $sample->setSampleFile($sampleFileName);
         $sample->setSampleUrl(null);
     }
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:14,代码来源:SampleRepository.php

示例9: decodeShippingDetails

 public function decodeShippingDetails($shippingDetailsEnc)
 {
     $decoded = array();
     if (!is_null($shippingDetailsEnc) && $shippingDetailsEnc != '') {
         $decoded = $this->jsonHelper->jsonDecode($shippingDetailsEnc);
     }
     return $decoded;
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:8,代码来源:Data.php

示例10: getFiles

 /**
  * @param array $item
  * @return array
  */
 protected function getFiles(array $item)
 {
     $files = [];
     if (isset($item[self::FIELD_FILE]) && $item[self::FIELD_FILE]) {
         $files = $this->jsonHelper->jsonDecode($item[self::FIELD_FILE]);
     }
     return $files;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:AbstractTypeHandler.php

示例11: execute

 /**
  * @return $this|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $paymentMethodNonce = $this->getRequest()->getParam('payment_method_nonce');
     $details = $this->getRequest()->getParam('details');
     if (!empty($details)) {
         $details = $this->jsonHelper->jsonDecode($details);
     }
     try {
         $this->initCheckout();
         if ($paymentMethodNonce && $details) {
             if (!$this->braintreePayPalConfig->isBillingAddressEnabled()) {
                 unset($details['billingAddress']);
             }
             $this->getCheckout()->initializeQuoteForReview($paymentMethodNonce, $details);
             $paymentMethod = $this->getQuote()->getPayment()->getMethodInstance();
             $paymentMethod->validate();
         } else {
             $paymentMethod = $this->getQuote()->getPayment()->getMethodInstance();
             if (!$paymentMethod || $paymentMethod->getCode() !== PayPal::METHOD_CODE) {
                 $this->messageManager->addErrorMessage(__('Incorrect payment method.'));
                 /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
                 $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
                 return $resultRedirect->setPath('checkout/cart');
             }
             $this->getQuote()->setMayEditShippingMethod(true);
         }
         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
         /** @var \Magento\Braintree\Block\Checkout\Review $reviewBlock */
         $reviewBlock = $resultPage->getLayout()->getBlock('braintree.paypal.review');
         $reviewBlock->setQuote($this->getQuote());
         $reviewBlock->getChildBlock('shipping_method')->setQuote($this->getQuote());
         return $resultPage;
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addExceptionMessage($e, $e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, __('We can\'t initialize checkout review.'));
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('checkout/cart');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:45,代码来源:Review.php

示例12: _afterLoad

 /**
  * Set model data from info field
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     $info = $this->jsonHelper->jsonDecode($this->getInfo());
     if (is_array($info)) {
         foreach ($info as $key => $value) {
             $this->setData($key, $value);
         }
     }
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:16,代码来源:Session.php

示例13: 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

示例14: unserializeProductPositions

 /**
  * Unserialize the sorted_products field of category if it is a string value.
  *
  * @param \Magento\Catalog\Model\Category $category Category
  *
  * @return array
  */
 private function unserializeProductPositions(\Magento\Catalog\Model\Category $category)
 {
     $productPositions = $category->getSortedProducts() ? $category->getSortedProducts() : [];
     if (is_string($productPositions)) {
         try {
             $productPositions = $this->jsonHelper->jsonDecode($productPositions);
         } catch (\Exception $e) {
             $productPositions = [];
         }
     }
     $category->setSortedProducts($productPositions);
     return $this;
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:20,代码来源:SaveProductsPositions.php

示例15: setFiles

 /**
  * Load files and set paths to link and sample of link
  *
  * @param LinkInterface $link
  * @return void
  */
 protected function setFiles(LinkInterface $link)
 {
     if ($link->getSampleType() == \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE && $link->getSampleFileData()) {
         $linkSampleFileName = $this->downloadableFile->moveFileFromTmp($link->getBaseSampleTmpPath(), $link->getBaseSamplePath(), $this->jsonHelper->jsonDecode($link->getSampleFileData()));
         $link->setSampleFile($linkSampleFileName);
         $link->setSampleUrl(null);
     }
     if ($link->getLinkType() == \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE && $link->getFile()) {
         $linkFileName = $this->downloadableFile->moveFileFromTmp($link->getBaseTmpPath(), $link->getBasePath(), $this->jsonHelper->jsonDecode($link->getFile()));
         $link->setLinkFile($linkFileName);
         $link->setLinkUrl(null);
     }
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:19,代码来源:LinkRepository.php


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