/** * Assign data to info model instance * * @param array|\Magento\Framework\DataObject $data * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @api */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); if (!$data instanceof \Magento\Framework\DataObject) { $data = new \Magento\Framework\DataObject($data); } $this->_logger->debug(__METHOD__ . ':' . $data->getData('customerDob')); /** @var \Magento\Quote\Model\Quote\Payment $infoInstance */ $infoInstance = $this->getInfoInstance(); $infoInstance->setAdditionalInformation('customerDob', $data->getData('customerDob')); return $this; }
/** * Build response for ajax request * * @param \Magento\Catalog\Model\Category $category * @param \Magento\Backend\Model\View\Result\Page $resultPage * * @return \Magento\Framework\Controller\Result\Json * * @deprecated */ protected function ajaxRequestResponse($category, $resultPage) { // prepare breadcrumbs of selected category, if any $breadcrumbsPath = $category->getPath(); if (empty($breadcrumbsPath)) { // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session $breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true); if (!empty($breadcrumbsPath)) { $breadcrumbsPath = explode('/', $breadcrumbsPath); // no need to get parent breadcrumbs if deleting category level 1 if (count($breadcrumbsPath) <= 1) { $breadcrumbsPath = ''; } else { array_pop($breadcrumbsPath); $breadcrumbsPath = implode('/', $breadcrumbsPath); } } } $eventResponse = new \Magento\Framework\DataObject(['content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml() . $resultPage->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(), 'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()]); $this->_eventManager->dispatch('category_prepare_ajax_response', ['response' => $eventResponse, 'controller' => $this]); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->_objectManager->get('Magento\\Framework\\Controller\\Result\\Json'); $resultJson->setHeader('Content-type', 'application/json', true); $resultJson->setData($eventResponse->getData()); return $resultJson; }
/** * Tests \Magento\Framework\DataObject->__construct() */ public function testConstruct() { $object = new \Magento\Framework\DataObject(); $this->assertEquals([], $object->getData()); $data = ['test' => 'test']; $object = new \Magento\Framework\DataObject($data); $this->assertEquals($data, $object->getData()); }
/** * After save process * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); $condition = ['option_id = ?' => $object->getId(), 'store_id = ? OR store_id = 0' => $object->getStoreId()]; $connection = $this->getConnection(); $connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition); $data = new \Magento\Framework\DataObject(); $data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle()); $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); /** * also saving default value if this store view scope */ if ($object->getStoreId()) { $data->setStoreId(0); $data->setTitle($object->getDefaultTitle()); $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); } return $this; }
/** * Assign data to info model instance * * @param array|\Magento\Framework\DataObject $data * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @api */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); if (!$data instanceof \Magento\Framework\DataObject) { $data = new \Magento\Framework\DataObject($data); } /** @var \Magento\Quote\Model\Quote\Payment $infoInstance */ $infoInstance = $this->getInfoInstance(); $infoInstance->setAdditionalInformation('financialInstitution', $data->getData('financialInstitution')); return $this; }
public function testBeforeSave() { $object = new \Magento\Framework\DataObject([self::ATTRIBUTE_NAME => ['is_in_stock' => 1, 'qty' => 5], 'stock_data' => ['is_in_stock' => 2, 'qty' => 2]]); $stockData = $object->getStockData(); $this->assertEquals(2, $stockData['is_in_stock']); $this->assertEquals(2, $stockData['qty']); $this->assertNotEmpty($object->getData(self::ATTRIBUTE_NAME)); $this->model->beforeSave($object); $stockData = $object->getStockData(); $this->assertEquals(1, $stockData['is_in_stock']); $this->assertEquals(5, $stockData['qty']); $this->assertNull($object->getData(self::ATTRIBUTE_NAME)); }
/** * Assign corresponding data * * @param \Magento\Framework\DataObject|mixed $data * * @return $this * @throws LocalizedException */ public function assignData(\Magento\Framework\DataObject $data) { // route /checkout/onepage/savePayment if (!$data instanceof \Magento\Framework\DataObject) { $data = new \Magento\Framework\DataObject($data); } //get array info $info_form = $data->getData(); $this->_helperData->log("info form", self::LOG_NAME, $info_form); $info = $this->getInfoInstance(); $info->setAdditionalInformation('payment_method', $info_form['payment_method_ticket']); if (!empty($info_form['coupon_code'])) { $info->setAdditionalInformation('coupon_code', $info_form['coupon_code']); } return $this; }
/** * Report action init operations * * @param array|\Magento\Framework\DataObject $blocks * @return $this */ public function _initReportAction($blocks) { if (!is_array($blocks)) { $blocks = [$blocks]; } $requestData = $this->_objectManager->get('Magento\\Backend\\Helper\\Data')->prepareFilterString($this->getRequest()->getParam('filter')); $inputFilter = new \Zend_Filter_Input(['from' => $this->_dateFilter, 'to' => $this->_dateFilter], [], $requestData); $requestData = $inputFilter->getUnescaped(); $requestData['store_ids'] = $this->getRequest()->getParam('store_ids'); $params = new \Magento\Framework\DataObject(); foreach ($requestData as $key => $value) { if (!empty($value)) { $params->setData($key, $value); } } foreach ($blocks as $block) { if ($block) { $block->setPeriodType($params->getData('period_type')); $block->setFilterData($params); } } return $this; }
/** * Check if product can be bought * * @param \Magento\Catalog\Model\Product $product * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function checkProductBuyState($product) { parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { $buyRequest = new \Magento\Framework\DataObject(unserialize($option->getValue())); if (!$buyRequest->hasLinks()) { if (!$product->getLinksPurchasedSeparately()) { $allLinksIds = $this->_linksFactory->create()->addProductToFilter($product->getEntityId())->getAllIds(); $buyRequest->setLinks($allLinksIds); $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).')); } } } return $this; }
/** * Load data * * @param bool $printQuery * @param bool $logQuery * @return $this */ public function load($printQuery = false, $logQuery = false) { if ($this->isLoaded()) { return $this; } $this->_beforeLoad(); $this->_renderFilters()->_renderOrders()->_renderLimit(); $this->printLogQuery($printQuery, $logQuery); $data = $this->getData(); $this->resetData(); $stores = $this->_storeCollectionFactory->create()->setWithoutDefaultFilter()->load()->toOptionHash(); $this->_items = []; foreach ($data as $v) { $storeObject = new \Magento\Framework\DataObject($v); $storeId = $v['store_id']; $storeName = isset($stores[$storeId]) ? $stores[$storeId] : null; $storeObject->setStoreName($storeName)->setWebsiteId($this->_storeManager->getStore($storeId)->getWebsiteId())->setAvgNormalized($v['avgsale'] * $v['num_orders']); $this->_items[$storeId] = $storeObject; foreach (array_keys($this->_totals) as $key) { $this->_totals[$key] += $storeObject->getData($key); } } if ($this->_totals['num_orders']) { $this->_totals['avgsale'] = $this->_totals['base_lifetime'] / $this->_totals['num_orders']; } $this->_setIsLoaded(); $this->_afterLoad(); return $this; }
/** * Process $buyRequest and sets its options before saving configuration to some product item. * This method is used to attach additional parameters to processed buyRequest. * * $params holds parameters of what operation must be performed: * - 'current_config', \Magento\Framework\DataObject or array - current buyRequest * that configures product in this item, used to restore currently attached files * - 'files_prefix': string[a-z0-9_] - prefix that was added at frontend to names of file inputs, * so they won't intersect with other submitted options * * @param \Magento\Framework\DataObject|array $buyRequest * @param \Magento\Framework\DataObject|array $params * @return \Magento\Framework\DataObject */ public function addParamsToBuyRequest($buyRequest, $params) { if (is_array($buyRequest)) { $buyRequest = new \Magento\Framework\DataObject($buyRequest); } if (is_array($params)) { $params = new \Magento\Framework\DataObject($params); } // Ensure that currentConfig goes as \Magento\Framework\DataObject - for easier work with it later $currentConfig = $params->getCurrentConfig(); if ($currentConfig) { if (is_array($currentConfig)) { $params->setCurrentConfig(new \Magento\Framework\DataObject($currentConfig)); } elseif (!$currentConfig instanceof \Magento\Framework\DataObject) { $params->unsCurrentConfig(); } } /* * Notice that '_processing_params' must always be object to protect processing forged requests * where '_processing_params' comes in $buyRequest as array from user input */ $processingParams = $buyRequest->getData('_processing_params'); if (!$processingParams || !$processingParams instanceof \Magento\Framework\DataObject) { $processingParams = new \Magento\Framework\DataObject(); $buyRequest->setData('_processing_params', $processingParams); } $processingParams->addData($params->getData()); return $buyRequest; }
/** * Check for unique values existence * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws AlreadyExistsException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _checkUnique(\Magento\Framework\Model\AbstractModel $object) { $existent = []; $fields = $this->getUniqueFields(); if (!empty($fields)) { if (!is_array($fields)) { $this->_uniqueFields = [['field' => $fields, 'title' => $fields]]; } $data = new \Magento\Framework\DataObject($this->_prepareDataForSave($object)); $select = $this->getConnection()->select()->from($this->getMainTable()); foreach ($fields as $unique) { $select->reset(\Magento\Framework\DB\Select::WHERE); foreach ((array)$unique['field'] as $field) { $value = $data->getData($field); if ($value === null) { $select->where($field . ' IS NULL'); } else { $select->where($field . '=?', trim($value)); } } if ($object->getId() || $object->getId() === '0') { $select->where($this->getIdFieldName() . '!=?', $object->getId()); } $test = $this->getConnection()->fetchRow($select); if ($test) { $existent[] = $unique['title']; } } } if (!empty($existent)) { if (count($existent) == 1) { $error = new \Magento\Framework\Phrase('%1 already exists.', [$existent[0]]); } else { $error = new \Magento\Framework\Phrase('%1 already exist.', [implode(', ', $existent)]); } throw new AlreadyExistsException($error); } return $this; }
/** * Dispatch render after event * * @param null|string|array|\Magento\Framework\DataObject &$html * @return void */ protected function _dispatchRenderGroupedAfterEvent(&$html) { $transport = new \Magento\Framework\DataObject(['output' => $html]); $params = ['element_name' => $this->getNameInLayout(), 'layout' => $this->getLayout(), 'transport' => $transport]; $this->_eventManager->dispatch('view_message_block_render_grouped_html_after', $params); $html = $transport->getData('output'); }
/** * Return Wysiwyg config as \Magento\Framework\DataObject * * Config options description: * * enabled: Enabled Visual Editor or not * hidden: Show Visual Editor on page load or not * use_container: Wrap Editor contents into div or not * no_display: Hide Editor container or not (related to use_container) * translator: Helper to translate phrases in lib * files_browser_*: Files Browser (media, images) settings * encode_directives: Encode template directives with JS or not * * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values * @return \Magento\Framework\DataObject */ public function getConfig($data = []) { $config = new \Magento\Framework\DataObject(); $config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'height' => '500px', 'plugins' => []]); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) { $config->addData(['add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']]); } if (is_array($data)) { $config->addData($data); } if ($config->getData('add_variables')) { $settings = $this->_variableConfig->getWysiwygPluginSettings($config); $config->addData($settings); } if ($config->getData('add_widgets')) { $settings = $this->_widgetConfig->getPluginSettings($config); $config->addData($settings); } return $config; }
/** * Edit category page * * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { $storeId = (int) $this->getRequest()->getParam('store'); $parentId = (int) $this->getRequest()->getParam('parent'); $categoryId = (int) $this->getRequest()->getParam('id'); if ($storeId && !$categoryId && !$parentId) { $store = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId); $this->getRequest()->setParam('id', (int) $store->getRootCategoryId()); } $category = $this->_initCategory(true); if (!$category) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]); } /** * Check if we have data in session (if during category save was exception) */ $data = $this->_getSession()->getCategoryData(true); if (isset($data['general'])) { $category->addData($data['general']); } /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); /** * Build response for ajax request */ if ($this->getRequest()->getQuery('isAjax')) { // prepare breadcrumbs of selected category, if any $breadcrumbsPath = $category->getPath(); if (empty($breadcrumbsPath)) { // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session $breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true); if (!empty($breadcrumbsPath)) { $breadcrumbsPath = explode('/', $breadcrumbsPath); // no need to get parent breadcrumbs if deleting category level 1 if (count($breadcrumbsPath) <= 1) { $breadcrumbsPath = ''; } else { array_pop($breadcrumbsPath); $breadcrumbsPath = implode('/', $breadcrumbsPath); } } } $eventResponse = new \Magento\Framework\DataObject(['content' => $resultPage->getLayout()->getBlock('category.edit')->getFormHtml() . $resultPage->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(), 'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()]); $this->_eventManager->dispatch('category_prepare_ajax_response', ['response' => $eventResponse, 'controller' => $this]); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); $resultJson->setHeader('Content-type', 'application/json', true); $resultJson->setData($eventResponse->getData()); return $resultJson; } $resultPage->setActiveMenu('Magento_Catalog::catalog_categories'); $resultPage->getConfig()->getTitle()->prepend(__('Categories')); $resultPage->getConfig()->getTitle()->prepend($categoryId ? $category->getName() : __('Categories')); $resultPage->addBreadcrumb(__('Manage Catalog Categories'), __('Manage Categories')); $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { $block->setStoreId($storeId); } return $resultPage; }
/** * Prepare email template with variables * * @param Order $order * @return void */ protected function prepareTemplate(Order $order) { $transport = ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)]; $transport = new \Magento\Framework\DataObject($transport); $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport->getData()); parent::prepareTemplate($order); }