public function getAlists($json = false) { // return [1]; $id = $this->getRequest()->getParam('id'); $collection = $this->_testFactory->create()->setId($id); $listso = $this->_objectManager->create('Sugarcode\\Test\\Model\\Test')->load($id); $collection = unserialize($listso->getInListsGrid()); if (sizeof($collection) > 0) { if ($json) { $jsonLists = []; foreach ($collection as $usrid) { $jsonLists[$usrid] = 0; } return $this->_jsonEncoder->encode((object) $jsonLists); } else { return array_values($collection); } } else { if ($json) { return '{}'; } else { return []; } } }
/** * 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)); }
/** * {@inheritdoc} */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { /** @var State[] $stateIndexers */ $stateIndexers = []; $states = $this->statesFactory->create(); foreach ($states->getItems() as $state) { /** @var State $state */ $stateIndexers[$state->getIndexerId()] = $state; } foreach ($this->config->getIndexers() as $indexerId => $indexerConfig) { $expectedHashConfig = $this->encryptor->hash($this->encoder->encode($indexerConfig), Encryptor::HASH_VERSION_MD5); if (isset($stateIndexers[$indexerId])) { if ($stateIndexers[$indexerId]->getHashConfig() != $expectedHashConfig) { $stateIndexers[$indexerId]->setStatus(StateInterface::STATUS_INVALID); $stateIndexers[$indexerId]->setHashConfig($expectedHashConfig); $stateIndexers[$indexerId]->save(); } } else { /** @var State $state */ $state = $this->stateFactory->create(); $state->loadByIndexer($indexerId); $state->setHashConfig($expectedHashConfig); $state->setStatus(StateInterface::STATUS_INVALID); $state->save(); } } }
/** * Reports Modules and module changes to the database reporting_module_status table * * @return \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo */ public function report() { if ($this->config->isNewRelicEnabled()) { $moduleData = $this->collect->getModuleData(); if (count($moduleData['changes']) > 0) { foreach ($moduleData['changes'] as $change) { switch ($change['type']) { case Config::ENABLED: $modelData = ['type' => Config::MODULE_ENABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::DISABLED: $modelData = ['type' => Config::MODULE_DISABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::INSTALLED: $modelData = ['type' => Config::MODULE_INSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::UNINSTALLED: $modelData = ['type' => Config::MODULE_UNINSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; } /** @var \Magento\NewRelicReporting\Model\System $systemModel */ $systemModel = $this->systemFactory->create(); $systemModel->setData($modelData); $systemModel->save(); } } } return $this; }
/** * @return string */ public function getProductsJson() { $products = $this->getCategory()->getProductsPosition(); if (!empty($products)) { return $this->jsonEncoder->encode($products); } return '{}'; }
/** * Render single action as dropdown option html * * @param array $action * @param \Magento\Framework\DataObject $row * @return string */ protected function _toOptionHtml($action, \Magento\Framework\DataObject $row) { $actionAttributes = new \Magento\Framework\DataObject(); $actionCaption = ''; $this->_transformActionData($action, $actionCaption, $row); $htmlAttibutes = ['value' => $this->escapeHtml($this->_jsonEncoder->encode($action))]; $actionAttributes->setData($htmlAttibutes); return '<option ' . $actionAttributes->serialize() . '>' . $actionCaption . '</option>'; }
/** * Render block HTML * * @return string */ protected function _toHtml() { $localeCode = $this->_localeResolver->getLocaleCode(); // get days names $days = \Zend_Locale_Data::getList($localeCode, 'days'); $this->assign('days', array('wide' => $this->encoder->encode(array_values($days['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($days['format']['abbreviated'])))); // get months names $months = \Zend_Locale_Data::getList($localeCode, 'months'); $this->assign('months', array('wide' => $this->encoder->encode(array_values($months['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($months['format']['abbreviated'])))); // get "today" and "week" words $this->assign('today', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'relative', 0))); $this->assign('week', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'field', 'week'))); // get "am" & "pm" words $this->assign('am', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'am'))); $this->assign('pm', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'pm'))); // get first day of week and weekend days $this->assign('firstDay', (int) $this->_scopeConfig->getValue('general/locale/firstday', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $this->assign('weekendDays', $this->encoder->encode((string) $this->_scopeConfig->getValue('general/locale/weekend', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))); // define default format and tooltip format $this->assign('defaultFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_MEDIUM))); $this->assign('toolTipFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_LONG))); // get days and months for en_US locale - calendar will parse exactly in this locale $days = \Zend_Locale_Data::getList('en_US', 'days'); $months = \Zend_Locale_Data::getList('en_US', 'months'); $enUS = new \stdClass(); $enUS->m = new \stdClass(); $enUS->m->wide = array_values($months['format']['wide']); $enUS->m->abbr = array_values($months['format']['abbreviated']); $this->assign('enUS', $this->encoder->encode($enUS)); return parent::_toHtml(); }
/** * Reports a system cache flush to the database reporting_system_updates table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { $jsonData = ['status' => 'updated']; $modelData = ['type' => Config::FLUSH_CACHE, 'action' => $this->jsonEncoder->encode($jsonData)]; /** @var \Magento\NewRelicReporting\Model\System $systemModel */ $systemModel = $this->systemFactory->create(); $systemModel->setData($modelData); $systemModel->save(); } }
/** * Get object data as JSON * * @return string */ public function getDataAsJSON() { $result = []; $inputNames = $this->getInputNames(); if ($serializeData = $this->getSerializeData()) { $result = $serializeData; } elseif (!empty($inputNames)) { return '{}'; } return $this->_jsonEncoder->encode($result); }
/** * Reports any products deleted to the database reporting_system_updates table * * @param Observer $observer * @return void */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { /** @var \Magento\Catalog\Model\Product $product */ $product = $observer->getEvent()->getProduct(); $jsonData = ['id' => $product->getId(), 'status' => 'deleted']; $modelData = ['type' => Config::PRODUCT_CHANGE, 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)]; /** @var \Magento\NewRelicReporting\Model\System $systemModel */ $systemModel = $this->systemFactory->create(); $systemModel->setData($modelData); $systemModel->save(); } }
/** * Reports concurrent admins to the database reporting_users table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->backendAuthSession->isLoggedIn()) { $user = $this->backendAuthSession->getUser(); $jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()]; $modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)]; /** @var \Magento\NewRelicReporting\Model\Users $usersModel */ $usersModel = $this->usersFactory->create(); $usersModel->setData($modelData); $usersModel->save(); } } }
/** * Reports concurrent users to the database reporting_users table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->customerSession->isLoggedIn()) { $customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()]; $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)]; /** @var \Magento\NewRelicReporting\Model\Users $usersModel */ $usersModel = $this->usersFactory->create(); $usersModel->setData($modelData); $usersModel->save(); } } }
/** * Render block HTML * * @return string */ protected function _toHtml() { $result = []; $layout = $this->getLayout(); foreach ($this->getChildNames() as $name) { $result[$name] = $layout->renderElement($name); } $resultJson = $this->_jsonEncoder->encode($result); $jsVarname = $this->getRequest()->getParam('as_js_varname'); if ($jsVarname) { return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson)); } else { return $resultJson; } }
/** * Get json representation of * * @return string */ public function getJsonConfig() { $config = []; foreach ($this->getOptions() as $option) { /* @var $option \Magento\Catalog\Model\Product\Option */ $priceValue = 0; if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) { $tmpPriceValues = []; foreach ($option->getValues() as $value) { /* @var $value \Magento\Catalog\Model\Product\Option\Value */ $id = $value->getId(); $tmpPriceValues[$id] = $this->_getPriceConfiguration($value); } $priceValue = $tmpPriceValues; } else { $priceValue = $this->_getPriceConfiguration($option); } $config[$option->getId()] = $priceValue; } $configObj = new \Magento\Framework\DataObject(['config' => $config]); //pass the return array encapsulated in an object for the other modules to be able to alter it eg: weee $this->_eventManager->dispatch('catalog_product_option_price_configuration_after', ['configObj' => $configObj]); $config = $configObj->getConfig(); return $this->_jsonEncoder->encode($config); }
/** * Get JSON encoded configuration array which can be used for JS dynamic * price calculation depending on product options * * @return string */ public function getJsonConfig() { $config = array(); if (!$this->hasOptions()) { return $this->_jsonEncoder->encode($config); } $customerId = $this->getCustomerId(); /* @var $product \Magento\Catalog\Model\Product */ $product = $this->getProduct(); $defaultTax = $this->taxCalculationService->getDefaultCalculatedRate($product->getTaxClassId(), $customerId); $currentTax = $this->taxCalculationService->getCalculatedRate($product->getTaxClassId(), $customerId); $tierPrices = array(); $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList(); foreach ($tierPricesList as $tierPrice) { $tierPrices[] = $this->_coreData->currency($tierPrice['price']->getValue(), false, false); } $config = array('productId' => $product->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat(), 'includeTax' => $this->_taxData->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => $this->_taxData->displayPriceIncludingTax(), 'showBothPrices' => $this->_taxData->displayBothPrices(), 'productPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getValue(), false, false), 'productOldPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false, false), 'inclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), false, false), 'exclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(), false, false), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => '_clone', 'oldPlusDisposition' => 0, 'plusDisposition' => 0, 'plusDispositionTax' => 0, 'oldMinusDisposition' => 0, 'minusDisposition' => 0, 'tierPrices' => $tierPrices); $responseObject = new \Magento\Framework\Object(); $this->_eventManager->dispatch('catalog_product_view_config', array('response_object' => $responseObject)); if (is_array($responseObject->getAdditionalOptions())) { foreach ($responseObject->getAdditionalOptions() as $option => $value) { $config[$option] = $value; } } return $this->_jsonEncoder->encode($config); }
/** * Get categories tree as recursive array * * @param int $parentId * @param bool $asJson * @param int $recursionLevel * @return array */ public function getTreeArray($parentId = null, $asJson = false, $recursionLevel = 3) { $productId = $this->_request->getParam('product'); if ($productId) { $product = $this->_productFactory->create()->setId($productId); $this->_allowedCategoryIds = $product->getCategoryIds(); unset($product); } $result = []; if ($parentId) { try { $category = $this->categoryRepository->get($parentId); } catch (NoSuchEntityException $e) { $category = null; } if ($category) { $tree = $this->_getNodesArray($this->getNode($category, $recursionLevel)); if (!empty($tree) && !empty($tree['children'])) { $result = $tree['children']; } } } else { $result = $this->_getNodesArray($this->getRoot(null, $recursionLevel)); } if ($asJson) { return $this->_jsonEncoder->encode($result); } $this->_allowedCategoryIds = []; return $result; }
/** * {@inheritdoc} */ public function create($productSku, DownloadableSampleContent $sampleContent, $isGlobalScopeContent = false) { $product = $this->productRepository->get($productSku, true); if ($product->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { throw new InputException('Product type of the product must be \'downloadable\'.'); } if (!$this->contentValidator->isValid($sampleContent)) { throw new InputException('Provided sample information is invalid.'); } if (!in_array($sampleContent->getSampleType(), array('url', 'file'))) { throw new InputException('Invalid sample type.'); } $title = $sampleContent->getTitle(); if (empty($title)) { throw new InputException('Sample title cannot be empty.'); } $sampleData = array('sample_id' => 0, 'is_delete' => 0, 'type' => $sampleContent->getSampleType(), 'sort_order' => $sampleContent->getSortOrder(), 'title' => $sampleContent->getTitle()); if ($sampleContent->getSampleType() == 'file') { $sampleData['file'] = $this->jsonEncoder->encode(array($this->fileContentUploader->upload($sampleContent->getSampleFile(), 'sample'))); } else { $sampleData['sample_url'] = $sampleContent->getSampleUrl(); } $downloadableData = array('sample' => array($sampleData)); $product->setDownloadableData($downloadableData); if ($isGlobalScopeContent) { $product->setStoreId(0); } $product->save(); return $product->getLastAddedSampleId(); }
/** * Retrieve validate button block * * @return \Magento\Backend\Block\Widget\Button */ public function getValidateButton() { if ($this->_validateButton === null) { /** @var $form \Magento\Framework\Data\Form */ $form = $this->_element->getForm(); $vatElementId = $this->_element->getHtmlId(); $countryElementId = $form->getElement('country_id')->getHtmlId(); $validateUrl = $this->_urlBuilder->getUrl('customer/system_config_validatevat/validateAdvanced'); $groupMessage = __('The customer is currently assigned to Customer Group %s.') . ' ' . __('Would you like to change the Customer Group for this order?'); $vatValidateOptions = $this->_jsonEncoder->encode(['vatElementId' => $vatElementId, 'countryElementId' => $countryElementId, 'groupIdHtmlId' => 'group_id', 'validateUrl' => $validateUrl, 'vatValidMessage' => __('The VAT ID is valid.'), 'vatInvalidMessage' => __('The VAT ID entered (%s) is not a valid VAT ID.'), 'vatValidAndGroupValidMessage' => __('The VAT ID is valid. The current Customer Group will be used.'), 'vatValidAndGroupInvalidMessage' => __('The VAT ID is valid but no Customer Group is assigned for it.'), 'vatValidAndGroupChangeMessage' => __('Based on the VAT ID, the customer would belong to the Customer Group %s.') . "\n" . $groupMessage, 'vatValidationFailedMessage' => __('There was an error validating the VAT ID. '), 'vatCustomerGroupMessage' => __('The customer would belong to Customer Group %s.'), 'vatGroupErrorMessage' => __('There was an error detecting Customer Group.')]); $optionsVarName = $this->getJsVariablePrefix() . 'VatParameters'; $beforeHtml = '<script>var ' . $optionsVarName . ' = ' . $vatValidateOptions . ';</script>'; $this->_validateButton = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Button')->setData(['label' => __('Validate VAT Number'), 'before_html' => $beforeHtml, 'onclick' => 'order.validateVat(' . $optionsVarName . ')']); } return $this->_validateButton; }
/** * Returns JSON encoded config to be used in JS scripts * * @return string * */ public function getJsonConfig() { /** @var Option[] $optionsArray */ $optionsArray = $this->getOptions(); $options = []; $currentProduct = $this->getProduct(); $defaultValues = []; $preConfiguredFlag = $currentProduct->hasPreconfiguredValues(); /** @var \Magento\Framework\Object|null $preConfiguredValues */ $preConfiguredValues = $preConfiguredFlag ? $currentProduct->getPreconfiguredValues() : null; $position = 0; foreach ($optionsArray as $optionItem) { /* @var $optionItem Option */ if (!$optionItem->getSelections()) { continue; } $optionId = $optionItem->getId(); $options[$optionId] = $this->getOptionItemData($optionItem, $currentProduct, $position); // Add attribute default value (if set) if ($preConfiguredFlag) { $configValue = $preConfiguredValues->getData('bundle_option/' . $optionId); if ($configValue) { $defaultValues[$optionId] = $configValue; } } $position++; } $config = $this->getConfigData($currentProduct, $options); if ($preConfiguredFlag && !empty($defaultValues)) { $config['defaultValues'] = $defaultValues; } return $this->jsonEncoder->encode($config); }
/** * @param bool $json * @return string|array */ public function getUsers($json = false) { if ($this->getRequest()->getParam('in_role_user') != "") { return $this->getRequest()->getParam('in_role_user'); } $roleId = $this->getRequest()->getParam('rid') > 0 ? $this->getRequest()->getParam('rid') : $this->_coreRegistry->registry('RID'); $users = $this->_roleFactory->create()->setId($roleId)->getRoleUsers(); if (sizeof($users) > 0) { if ($json) { $jsonUsers = []; foreach ($users as $usrid) { $jsonUsers[$usrid] = 0; } return $this->_jsonEncoder->encode((object) $jsonUsers); } else { return array_values($users); } } else { if ($json) { return '{}'; } else { return []; } } }
/** * @param \Magento\Catalog\Api\Data\ProductInterface $product * @param LinkInterface $link * @param bool $isGlobalScopeContent * @return int */ protected function saveLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent) { $linkData = ['link_id' => $link->getid() === null ? 0 : $link->getid(), 'is_delete' => 0, 'type' => $link->getLinkType(), 'sort_order' => $link->getSortOrder(), 'title' => $link->getTitle(), 'price' => $link->getPrice(), 'number_of_downloads' => $link->getNumberOfDownloads(), 'is_shareable' => $link->getIsShareable()]; if ($link->getLinkType() == 'file' && $link->getLinkFile() === null) { $linkData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getLinkFileContent(), 'link_file')]); } elseif ($link->getLinkType() === 'url') { $linkData['link_url'] = $link->getLinkUrl(); } else { //existing link file $linkData['file'] = $this->jsonEncoder->encode([['file' => $link->getLinkFile(), 'status' => 'old']]); } if ($link->getSampleType() == 'file' && $link->getSampleFile() === null) { $linkData['sample']['type'] = 'file'; $linkData['sample']['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getSampleFileContent(), 'link_sample_file')]); } elseif ($link->getSampleType() == 'url') { $linkData['sample']['type'] = 'url'; $linkData['sample']['url'] = $link->getSampleUrl(); } $downloadableData = ['link' => [$linkData]]; $product->setDownloadableData($downloadableData); if ($isGlobalScopeContent) { $product->setStoreId(0); } $this->downloadableType->save($product); return $product->getLastAddedLinkId(); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function save($productSku, SampleContentInterface $sampleContent, $sampleId = null, $isGlobalScopeContent = false) { $product = $this->productRepository->get($productSku, true); if ($sampleId) { /** @var $sample \Magento\Downloadable\Model\Sample */ $sample = $this->sampleFactory->create()->load($sampleId); if (!$sample->getId()) { throw new NoSuchEntityException(__('There is no downloadable sample with provided ID.')); } if ($sample->getProductId() != $product->getId()) { throw new InputException(__('Provided downloadable sample is not related to given product.')); } if (!$this->contentValidator->isValid($sampleContent)) { throw new InputException(__('Provided sample information is invalid.')); } if ($isGlobalScopeContent) { $product->setStoreId(0); } $title = $sampleContent->getTitle(); if (empty($title)) { if ($isGlobalScopeContent) { throw new InputException(__('Sample title cannot be empty.')); } // use title from GLOBAL scope $sample->setTitle(null); } else { $sample->setTitle($sampleContent->getTitle()); } $sample->setProductId($product->getId())->setStoreId($product->getStoreId())->setSortOrder($sampleContent->getSortOrder())->save(); return $sample->getId(); } else { if ($product->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { throw new InputException(__('Product type of the product must be \'downloadable\'.')); } if (!$this->contentValidator->isValid($sampleContent)) { throw new InputException(__('Provided sample information is invalid.')); } if (!in_array($sampleContent->getSampleType(), ['url', 'file'])) { throw new InputException(__('Invalid sample type.')); } $title = $sampleContent->getTitle(); if (empty($title)) { throw new InputException(__('Sample title cannot be empty.')); } $sampleData = ['sample_id' => 0, 'is_delete' => 0, 'type' => $sampleContent->getSampleType(), 'sort_order' => $sampleContent->getSortOrder(), 'title' => $sampleContent->getTitle()]; if ($sampleContent->getSampleType() == 'file') { $sampleData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($sampleContent->getSampleFile(), 'sample')]); } else { $sampleData['sample_url'] = $sampleContent->getSampleUrl(); } $downloadableData = ['sample' => [$sampleData]]; $product->setDownloadableData($downloadableData); if ($isGlobalScopeContent) { $product->setStoreId(0); } $product->save(); return $product->getLastAddedSampleId(); } }
/** * Prepare Layout Content */ protected function _prepareLayout() { $model = $this->coreRegistry->registry('easytab'); $values = $model->getData(); $values = isset($values['tab_id']) ? $this->jsonEncoder->encode($values) : 'false'; $this->_formScripts[] = "\n require([\n 'jquery',\n 'tabOptions'\n ], function (\$, tabOptions) {\n tabOptions.init('" . $this->getUrl("easytabs/*/loadOptions") . "', " . $values . ");\n });\n "; return parent::_prepareLayout(); }
/** * Retrieve massaction items JSON * * @return string */ public function getItemsJson() { $result = array(); foreach ($this->getItems() as $itemId => $item) { $result[$itemId] = $item->toArray(); } return $this->_jsonEncoder->encode($result); }
/** * Return response as JSON. * * @return string */ public function getResponseJson() { // add messages HTML if it is not already specified if (!isset($this->_actions['import_validation_messages'])) { $this->addAction('innerHTML', 'import_validation_messages', $this->getMessagesHtml()); } return $this->_jsonEncoder->encode($this->_actions); }
/** * @return string */ public function getJsonConfig() { $finalPrice = $this->getProduct()->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE); $linksConfig = []; foreach ($this->getLinks() as $link) { $amount = $finalPrice->getCustomAmount($link->getPrice()); $linksConfig[$link->getId()] = ['finalPrice' => $amount->getValue(), 'basePrice' => $amount->getBaseAmount()]; } return $this->encoder->encode(['links' => $linksConfig]); }
/** * Reports any products created or updated to the database reporting_system_updates table * * @param Observer $observer * @return void */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { /** @var \Magento\Catalog\Model\Product $product */ $product = $observer->getEvent()->getProduct(); $jsonData = ['name' => $product->getName()]; if ($product->isObjectNew()) { $jsonData['status'] = 'created'; } else { $jsonData['id'] = $product->getId(); $jsonData['status'] = 'updated'; } $modelData = ['type' => Config::PRODUCT_CHANGE, 'action' => $this->jsonEncoder->encode($jsonData)]; /** @var \Magento\NewRelicReporting\Model\System $systemModel */ $systemModel = $this->systemFactory->create(); $systemModel->setData($modelData); $systemModel->save(); } }
/** * Attach new category dialog widget initialization * * @return string */ public function getAfterElementHtml() { $widgetOptions = $this->_jsonEncoder->encode(array('suggestOptions' => array('source' => $this->getUrl('catalog/category/suggestCategories'), 'valueField' => '#new_category_parent', 'className' => 'category-select', 'multiselect' => true, 'showAll' => true), 'saveCategoryUrl' => $this->getUrl('catalog/category/save'))); return <<<HTML <script> (function(\$) { // waiting for page to load to have '#category_ids-template' available \$('#new-category').mage('newCategoryDialog', {$widgetOptions}); })(jQuery); </script> HTML; }
/** * Return Customer Address Collection as JSON * * @return string */ public function getAddressCollectionJson() { $defaultCountryId = $this->_coreData->getDefaultCountry($this->getStore()); $emptyAddressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address', array(\Magento\Customer\Service\V1\Data\Address::KEY_COUNTRY_ID => $defaultCountryId)); $data = array(0 => $emptyAddressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON)); foreach ($this->getAddressCollection() as $addressData) { $addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address', AddressConverter::toFlatArray($addressData)); $data[$addressData->getId()] = $addressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON); } return $this->_jsonEncoder->encode($data); }
/** * Retrieve config json * * @param string $type * @return string */ public function getConfigJson($type = 'links') { $this->getConfig()->setUrl($this->getUploadUrl($type)); $this->getConfig()->setParams(['form_key' => $this->getFormKey()]); $this->getConfig()->setFileField($this->getFileFieldName($type)); $this->getConfig()->setFilters(['all' => ['label' => __('All Files'), 'files' => ['*.*']]]); $this->getConfig()->setReplaceBrowseWithRemove(true); $this->getConfig()->setWidth('32'); $this->getConfig()->setHideUploadButton(true); return $this->_jsonEncoder->encode($this->getConfig()->getData()); }