private function validateConfigurable($product, $attributeSetId, $storeId) { $type = $product->getTypeInstance(); //var_dump(\Magento\Store\Model\ScopeInterface::SCOPE_STORE);die(); $auto = $this->scopeConfig->getValue('catalog/configurable_value/auto_create', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if (!$type instanceof Configurable) { return true; } $attributeSet = $this->attributeSetFactory->create()->load($attributeSetId); $attributes = $this->configurableProduct->getUsedProductAttributes($product); $attributeSet->addSetInfo($this->entityFactory->create()->setType(\Magento\Catalog\Model\Product::ENTITY)->getTypeId(), $attributes); foreach ($type->getConfigurableAttributes($product) as $configAattribute) { $attribute = $configAattribute->getProductAttribute(); if (!is_null($attribute)) { //var_dump($attribute->isInSet($attributeSetId));die(); if (!$attribute->isInSet($attributeSetId)) { if ($auto) { $attribute->setAttributeSetId($attributeSetId)->setAttributeGroupId($attributeSet->getDefaultGroupId($attributeSetId))->save(); return true; } else { $this->messageManager->addError(__('The configurable attribute ' . $attribute->getAttributeCode() . ' is not available in the targeted attribute set. Please create it first! Or allow create it from global config Catalog->Change Attribte Set')); return false; } } else { return true; } } } }
/** * Index Action* * @return void */ public function execute() { /** @var \MAgento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Tym17_AdminSample::sampleTwo'); /*$resultPage->addBreadcrumb(__('System'), __('System')); This also changes page title in tab name $resultPage->addBreadcrumb(__('SampleTwo'), __('SampleTwo'));*/ $resultPage->getConfig()->getTitle()->prepend(__('SampleTwo Title')); // Changing the page title // You will notice that this block 'Two' is defined in the template file $resultPage->getLayout()->getBlock('Two')->setSampleText('This text is passed'); // Here we use Magento2's Magic getsetters // Retrieving config value and passing it to template $cfg_text = $this->scopeConfig->getValue('adminsample/txt/textsample'); $resultPage->getLayout()->getBlock('Two')->setCfgSample($cfg_text); return $resultPage; }
/** * Index Action * * @return void */ public function execute() { $this->_eventManager->dispatch('mperf_request', ['from' => 'Settings']); $resultPage = $this->resultPageFactory->create(); return $this->_config->checkLinked($resultPage, $this->resultRedirectFactory, 'Settings'); }