/**
  * @param int|bool $storeId
  * @return \Magento\Store\Model\Website
  */
 protected function getWebsite($storeId)
 {
     if ($storeId) {
         $websiteId = $this->storeRepository->getById($storeId)->getWebsiteId();
         $website = $this->websiteRepository->getById($websiteId);
     } else {
         $website = $this->websiteRepository->getDefault();
     }
     return $website;
 }
Beispiel #2
0
 /**
  * Prepares children for the parent fieldset
  *
  * @return array
  */
 protected function getFieldsForFieldset()
 {
     $children = [];
     $websiteIds = $this->getWebsitesValues();
     $websitesList = $this->getWebsitesList();
     $isNewProduct = !$this->locator->getProduct()->getId();
     $tooltip = ['link' => 'http://docs.magento.com/m2/ce/user_guide/configuration/scope.html', 'description' => __('If your Magento site has multiple views, ' . 'you can set the scope to apply to a specific view.')];
     $sortOrder = 0;
     $label = __('Websites');
     $defaultWebsiteId = $this->websiteRepository->getDefault()->getId();
     foreach ($websitesList as $website) {
         $isChecked = in_array($website['id'], $websiteIds) || $defaultWebsiteId == $website['id'] && $isNewProduct;
         $children[$website['id']] = ['arguments' => ['data' => ['config' => ['dataType' => Form\Element\DataType\Number::NAME, 'componentType' => Form\Field::NAME, 'formElement' => Form\Element\Checkbox::NAME, 'description' => __($website['name']), 'tooltip' => $tooltip, 'sortOrder' => $sortOrder, 'dataScope' => 'website_ids.' . $website['id'], 'label' => $label, 'valueMap' => ['true' => (string) $website['id'], 'false' => '0'], 'value' => $isChecked ? (string) $website['id'] : '0']]]];
         $sortOrder++;
         $tooltip = null;
         $label = ' ';
         if (!$isNewProduct && !in_array($website['id'], $websiteIds) && $website['storesCount']) {
             $children['copy_to_stores.' . $website['id']] = $this->getDynamicRow($website['id'], $sortOrder);
             $sortOrder++;
         }
     }
     return $children;
 }
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreId($scopeCode)
 {
     $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
     return $this->groupRepository->get($website->getDefaultGroupId())->getDefaultStoreId();
 }
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreView()
 {
     $defaultWebsite = $this->websiteRepository->getDefault();
     $defaultStore = $this->getGroup($defaultWebsite->getDefaultGroupId())->getDefaultStore();
     return $defaultStore ?: null;
 }