/** * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->load($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(__('We can\'t get the product ID.')); } $this->getResponse()->representJson($response->toJSON()); }
/** * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = $this->productRepository->getById($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(__('We can\'t get the product ID.')); } $this->getResponse()->representJson($response->toJSON()); }
/** * Load customer group collection data from service * * @param bool $printQuery * @param bool $logQuery * @return $this */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { $searchCriteria = $this->getSearchCriteria(); $searchResults = $this->groupService->searchGroups($searchCriteria); $this->_totalRecords = $searchResults->getTotalCount(); /** @var CustomerGroup[] $groups */ $groups = $searchResults->getItems(); foreach ($groups as $group) { $groupItem = new \Magento\Framework\Object(); $groupItem->addData(\Magento\Framework\Service\DataObjectConverter::toFlatArray($group)); $this->_addItem($groupItem); } $this->_setIsLoaded(); } return $this; }
/** * Load customer group collection data from service * * @param bool $printQuery * @param bool $logQuery * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { $searchCriteria = $this->getSearchCriteria(); $searchResults = $this->groupRepository->getList($searchCriteria); $this->_totalRecords = $searchResults->getTotalCount(); /** @var GroupInterface[] $groups */ $groups = $searchResults->getItems(); foreach ($groups as $group) { $groupItem = new \Magento\Framework\Object(); $groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group, '\\Magento\\Customer\\Api\\Data\\GroupInterface')); $this->_addItem($groupItem); } $this->_setIsLoaded(); } return $this; }
/** * Extracts information from backup's filename * * @param string $filename * @return \Magento\Framework\Object */ public function extractDataFromFilename($filename) { $extensions = $this->getExtensions(); $filenameWithoutExtension = $filename; foreach ($extensions as $extension) { $filenameWithoutExtension = preg_replace('/' . preg_quote($extension, '/') . '$/', '', $filenameWithoutExtension); } $filenameWithoutExtension = substr($filenameWithoutExtension, 0, strrpos($filenameWithoutExtension, ".")); list($time, $type) = explode("_", $filenameWithoutExtension); $name = str_replace($time . '_' . $type, '', $filenameWithoutExtension); if (!empty($name)) { $name = substr($name, 1); } $result = new \Magento\Framework\Object(); $result->addData(['name' => $name, 'type' => $type, 'time' => $time]); return $result; }
/** * Parse buyRequest into options values used by product * * @param \Magento\Framework\Object $buyRequest * @return \Magento\Framework\Object */ public function processBuyRequest(\Magento\Framework\Object $buyRequest) { $options = new \Magento\Framework\Object(); /* add product custom options data */ $customOptions = $buyRequest->getOptions(); if (is_array($customOptions)) { array_filter($customOptions, function ($value) { return $value !== ''; }); $options->setOptions($customOptions); } /* add product type selected options data */ $type = $this->getTypeInstance(); $typeSpecificOptions = $type->processBuyRequest($this, $buyRequest); $options->addData($typeSpecificOptions); /* check correctness of product's options */ $options->setErrors($type->checkProductConfiguration($this, $buyRequest)); return $options; }
/** * Checking quote item quantity * * Second parameter of this method specifies quantity of this product in whole shopping cart * which should be checked for stock availability * * @param int|float $qty quantity of this item (item qty x parent item qty) * @param int|float $summaryQty quantity of this product * @param int|float $origQty original qty of item (not multiplied on parent item qty) * @return \Magento\Framework\Object */ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) { $result = new \Magento\Framework\Object(); $result->setHasError(false); if (!is_numeric($qty)) { $qty = $this->_localeFormat->getNumber($qty); } /** * Check quantity type */ $result->setItemIsQtyDecimal($this->getIsQtyDecimal()); if (!$this->getIsQtyDecimal()) { $result->setHasQtyOptionUpdate(true); $qty = intval($qty); /** * Adding stock data to quote item */ $result->setItemQty($qty); if (!is_numeric($qty)) { $qty = $this->_localeFormat->getNumber($qty); } $origQty = intval($origQty); $result->setOrigQty($origQty); } if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) { $result->setHasError(true)->setMessage(__('The fewest you may purchase is %1.', $this->getMinSaleQty() * 1))->setErrorCode('qty_min')->setQuoteMessage(__('Please correct the quantity for some products.'))->setQuoteMessageIndex('qty'); return $result; } if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) { $result->setHasError(true)->setMessage(__('The most you may purchase is %1.', $this->getMaxSaleQty() * 1))->setErrorCode('qty_max')->setQuoteMessage(__('Please correct the quantity for some products.'))->setQuoteMessageIndex('qty'); return $result; } $result->addData($this->checkQtyIncrements($qty)->getData()); if ($result->getHasError()) { return $result; } if (!$this->getManageStock()) { return $result; } if (!$this->getIsInStock()) { $result->setHasError(true)->setMessage(__('This product is out of stock.'))->setQuoteMessage(__('Some of the products are currently out of stock.'))->setQuoteMessageIndex('stock'); $result->setItemUseOldQty(true); return $result; } if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) { $message = __('We don\'t have as many "%1" as you requested.', $this->getProductName()); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty'); return $result; } else { if ($this->getQty() - $summaryQty < 0) { if ($this->getProductName()) { if ($this->getIsChildItem()) { $backOrderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1; if ($backOrderQty > $qty) { $backOrderQty = $qty; } $result->setItemBackorders($backOrderQty); } else { $orderedItems = (int) $this->getOrderedItems(); // Available item qty in stock excluding item qty in other quotes $qtyAvailable = ($this->getQty() - ($summaryQty - $qty)) * 1; if ($qtyAvailable > 0) { $backOrderQty = $qty * 1 - $qtyAvailable; } else { $backOrderQty = $qty * 1; } if ($backOrderQty > 0) { $result->setItemBackorders($backOrderQty); } $this->setOrderedItems($orderedItems + $qty); } if ($this->getBackorders() == \Magento\CatalogInventory\Model\Stock::BACKORDERS_YES_NOTIFY) { if (!$this->getIsChildItem()) { $result->setMessage(__('We don\'t have as many "%1" as you requested, but we\'ll back order the remaining %2.', $this->getProductName(), $backOrderQty * 1)); } else { $result->setMessage(__('We don\'t have "%1" in the requested quantity, so we\'ll back order the remaining %2.', $this->getProductName(), $backOrderQty * 1)); } } elseif ($this->_hasDefaultNotificationMessage()) { $result->setMessage(__('We don\'t have as many "%1" as you requested.', $this->getProductName())); } } } else { if (!$this->getIsChildItem()) { $this->setOrderedItems($qty + (int) $this->getOrderedItems()); } } } return $result; }
/** * Prepare product * * @param array $productRow * @param int $storeId * @return \Magento\Framework\Object */ protected function _prepareProduct(array $productRow, $storeId) { $product = new \Magento\Framework\Object(); $product['id'] = $productRow[$this->getIdFieldName()]; if (empty($productRow['url'])) { $productRow['url'] = 'catalog/product/view/id/' . $product->getId(); } $product->addData($productRow); $this->_loadProductImages($product, $storeId); return $product; }
/** * Retrieve form data * * @return mixed */ public function getFormData() { $data = $this->getData('form_data'); if ($data === null) { $formData = $this->_customerSession->getCustomerFormData(true); $data = new \Magento\Framework\Object(); if ($formData) { $data->addData($formData); $data->setCustomerData(1); } if (isset($data['region_id'])) { $data['region_id'] = (int) $data['region_id']; } $this->setData('form_data', $data); } return $data; }
/** * Prepare helper block * * @param array $data * @return array */ protected function prepareHelperBlock(array $data) { if (isset($data['helper_block'])) { $helper = new \Magento\Framework\Object(); if (isset($data['helper_block']['data']) && is_array($data['helper_block']['data'])) { $helper->addData($data['helper_block']['data']); } if (isset($data['helper_block']['type'])) { $helper->setType($data['helper_block']['type']); } $data['helper_block'] = $helper; } return $data; }
/** * Return Wysiwyg config as \Magento\Framework\Object * * 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\Object $data Object constructor params to override default config values * @return \Magento\Framework\Object */ public function getConfig($data = []) { $config = new \Magento\Framework\Object(); $config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, '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%', '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; }
public function testUpdateItemByFirstMultiRow() { $item = new \Magento\Framework\Object(['test1' => '1']); // prepare sub-collection $subCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false)); $subCollection->addItem(new \Magento\Framework\Object(['test4' => '1', 'test5' => '2'])); $subCollection->addItem(new \Magento\Framework\Object(['test4' => '2', 'test5' => '2'])); $item->setChildren($subCollection); $expectedItem = new \Magento\Framework\Object(['test1' => '1']); $expectedItem->addData(['test4' => '1', 'test5' => '2']); $expectedItem->setChildren($subCollection); $this->_block->updateItemByFirstMultiRow($item); $this->assertEquals($expectedItem, $item); }
/** * Return widget XML configuration as \Magento\Framework\Object and makes some data preparations * * @param string $type Widget type * @return \Magento\Framework\Object */ public function getConfigAsObject($type) { $widget = $this->getWidgetByClassType($type); $object = new \Magento\Framework\Object(); if ($widget === null) { return $object; } $widget = $this->_getAsCanonicalArray($widget); // Save all nodes to object data $object->setType($type); $object->setData($widget); // Correct widget parameters and convert its data to objects $params = $object->getData('parameters'); $newParams = array(); if (is_array($params)) { $sortOrder = 0; foreach ($params as $key => $data) { if (is_array($data)) { $data['key'] = $key; $data['sort_order'] = isset($data['sort_order']) ? (int) $data['sort_order'] : $sortOrder; // prepare values (for drop-dawns) specified directly in configuration $values = array(); if (isset($data['values']) && is_array($data['values'])) { foreach ($data['values'] as $value) { if (isset($value['label']) && isset($value['value'])) { $values[] = $value; } } } $data['values'] = $values; // prepare helper block object if (isset($data['helper_block'])) { $helper = new \Magento\Framework\Object(); if (isset($data['helper_block']['data']) && is_array($data['helper_block']['data'])) { $helper->addData($data['helper_block']['data']); } if (isset($data['helper_block']['type'])) { $helper->setType($data['helper_block']['type']); } $data['helper_block'] = $helper; } $newParams[$key] = new \Magento\Framework\Object($data); $sortOrder++; } } } uasort($newParams, array($this, '_sortParameters')); $object->setData('parameters', $newParams); return $object; }