/**
  * 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\DataObject();
             $groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group, '\\Magento\\Customer\\Api\\Data\\GroupInterface'));
             $this->_addItem($groupItem);
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
 /**
  * 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\DataObject();
         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;
 }
Beispiel #3
0
 /**
  * Prepare helper block
  *
  * @param array $data
  * @return array
  */
 protected function prepareHelperBlock(array $data)
 {
     if (isset($data['helper_block'])) {
         $helper = new \Magento\Framework\DataObject();
         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;
 }
Beispiel #4
0
 /**
  * Parse buyRequest into options values used by product
  *
  * @param  \Magento\Framework\DataObject $buyRequest
  * @return \Magento\Framework\DataObject
  */
 public function processBuyRequest(\Magento\Framework\DataObject $buyRequest)
 {
     $options = new \Magento\Framework\DataObject();
     /* 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;
 }
Beispiel #5
0
 /**
  * Extracts information from backup's filename
  *
  * @param string $filename
  * @return \Magento\Framework\DataObject
  */
 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\DataObject();
     $result->addData(['name' => $name, 'type' => $type, 'time' => $time]);
     return $result;
 }
 /**
  * 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;
 }
Beispiel #7
0
 /**
  * Prepare product
  *
  * @param array $productRow
  * @param int $storeId
  * @return \Magento\Framework\DataObject
  */
 protected function _prepareProduct(array $productRow, $storeId)
 {
     $product = new \Magento\Framework\DataObject();
     $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;
 }
 public function testUpdateItemByFirstMultiRow()
 {
     $item = new \Magento\Framework\DataObject(['test1' => '1']);
     // prepare sub-collection
     $subCollection = new \Magento\Framework\Data\Collection($this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false));
     $subCollection->addItem(new \Magento\Framework\DataObject(['test4' => '1', 'test5' => '2']));
     $subCollection->addItem(new \Magento\Framework\DataObject(['test4' => '2', 'test5' => '2']));
     $item->setChildren($subCollection);
     $expectedItem = new \Magento\Framework\DataObject(['test1' => '1']);
     $expectedItem->addData(['test4' => '1', 'test5' => '2']);
     $expectedItem->setChildren($subCollection);
     $this->_block->updateItemByFirstMultiRow($item);
     $this->assertEquals($expectedItem, $item);
 }
 /**
  * Add product to quote
  *
  * This file was inspired by
  * @see dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_bundle_and_options.php
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Catalog\Model\Product $product
  * @param int $qty
  * @param $itemData
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function addProductToQuote(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, $qty, $itemData)
 {
     if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
         $quote->addProduct($product, $qty);
     } elseif ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
         $attribute = $this->getConfigurableAttribute(self::CONFIGURABLE_ATTRIBUTE_NAME);
         /** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $options */
         $options = $attribute->getOptions();
         array_shift($options);
         //remove the first option which is empty
         $requestInfo = new \Magento\Framework\DataObject();
         if (!empty($options)) {
             $option = $options[0];
             $requestData = ['qty' => $qty];
             /** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $option */
             $requestData['super_attribute'][$attribute->getId()] = $option->getValue();
             $requestInfo->addData($requestData);
         }
         $quote->addProduct($product, $requestInfo);
     } elseif ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
         /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
         //Load options
         $typeInstance = $product->getTypeInstance();
         $typeInstance->setStoreFilter($product->getStoreId(), $product);
         $optionCollection = $typeInstance->getOptionsCollection($product);
         $bundleOptions = [];
         $bundleOptionsQty = [];
         /** @var $option \Magento\Bundle\Model\Option */
         foreach ($optionCollection as $option) {
             $selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
             if ($option->isMultiSelection()) {
                 $selectionsCollection->load();
                 $bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
             } else {
                 $bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
             }
             $optionQty = 1;
             foreach ($itemData['bundled_options'] as $bundledOptionData) {
                 if ($option->getTitle() == $bundledOptionData['title']) {
                     $optionQty = $bundledOptionData['qty'];
                     break;
                 }
             }
             $bundleOptionsQty[$option->getId()] = $optionQty;
         }
         $requestInfo = new \Magento\Framework\DataObject(['qty' => $qty, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]);
         $quote->addProduct($product, $requestInfo);
     } else {
         throw new \Exception('Unrecognized type: ' . $product->getTypeId());
     }
 }