/** * Value constructor. * * @param \Magento\Eav\Model\ConfigFactory $configFactory * @param \Magento\Config\Model\Config\Source\Yesno $yesno * @param \Magento\Directory\Model\Config\Source\Country $country * @param \Magento\Directory\Model\Config\Source\Allregion $allregion * @param \Magento\Shipping\Model\Config\Source\Allmethods $allShippingMethods * @param \Magento\Payment\Model\Config\Source\Allmethods $allPaymentMethods * @param \Magento\Customer\Model\Config\Source\Group $group */ public function __construct(\Magento\Eav\Model\ConfigFactory $configFactory, \Magento\Config\Model\Config\Source\Yesno $yesno, \Magento\Directory\Model\Config\Source\Country $country, \Magento\Directory\Model\Config\Source\Allregion $allregion, \Magento\Shipping\Model\Config\Source\Allmethods $allShippingMethods, \Magento\Payment\Model\Config\Source\Allmethods $allPaymentMethods, \Magento\Customer\Model\Config\Source\Group $group) { $this->configFactory = $configFactory->create(); $this->yesno = $yesno; $this->country = $country; $this->allregion = $allregion; $this->allShippingMethods = $allShippingMethods; $this->allPaymentMethods = $allPaymentMethods; $this->group = $group; }
/** * @param string $attributeSetId * @param string $attributeId * @return bool * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function deleteAttribute($attributeSetId, $attributeId) { $attributeSet = $this->setFactory->create()->load($attributeSetId); if (!$attributeSet->getId()) { // Attribute set does not exist throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); } // check that attribute set has type catalog_product $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); if ($setEntityType->getEntityTypeCode() != \Magento\Catalog\Model\Product::ENTITY) { throw new InputException('Attribute with wrong attribute type is provided'); } // check if attribute with requested id exists $attribute = $this->attributeFactory->create()->load($attributeId); if (!$attribute->getId()) { // Attribute set does not exist throw NoSuchEntityException::singleField('attributeId', $attributeId); } // check if attribute is in set $attribute->setAttributeSetId($attributeSet->getId())->loadEntityAttributeIdBySet(); if (!$attribute->getEntityAttributeId()) { throw new InputException('Requested attribute is not in requested attribute set.'); } if (!$attribute->getIsUserDefined()) { throw new StateException('System attribute can not be deleted'); } $attribute->deleteEntity(); return true; }
/** * Get media gallery model * * @return \Magento\Catalog\Model\Product\Attribute\Backend\Media|null */ protected function _getMediaGalleryModel() { if ($this->_mediaGalleryModel === null) { /** @var $eavConfig \Magento\Eav\Model\Config */ $eavConfig = $this->_eavConfigFactory->create(); /** @var $eavConfig \Magento\Eav\Model\Attribute */ $mediaGallery = $eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'media_gallery'); $this->_mediaGalleryModel = $mediaGallery->getBackend(); } return $this->_mediaGalleryModel; }
/** * {@inheritdoc} */ public function unassign($attributeSetId, $attributeCode) { try { $attributeSet = $this->setRepository->get($attributeSetId); } catch (NoSuchEntityException $e) { throw new NoSuchEntityException(__('Attribute set not found: %1', $attributeSetId)); } $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ $attribute = $this->attributeRepository->get($setEntityType->getEntityTypeCode(), $attributeCode); // Check if attribute is in set $attribute->setAttributeSetId($attributeSet->getAttributeSetId()); $attribute->loadEntityAttributeIdBySet(); if (!$attribute->getEntityAttributeId()) { throw new InputException(__('Attribute "%1" not found in attribute set %2.', $attributeCode, $attributeSetId)); } if (!$attribute->getIsUserDefined()) { throw new StateException(__('System attribute can not be deleted')); } $attribute->deleteEntity(); return true; }
/** * Type constructor. * * @param \Magento\Eav\Model\ConfigFactory $configFactory * @param \Magento\SalesRule\Model\Rule\Condition\ProductFactory $productFactory */ public function __construct(\Magento\Eav\Model\ConfigFactory $configFactory, \Magento\SalesRule\Model\Rule\Condition\ProductFactory $productFactory) { $this->_configFactory = $configFactory->create(); $this->_productFactory = $productFactory->create(); }
public function __construct(\Magento\Eav\Model\ConfigFactory $configFactory, \Magento\Framework\ObjectManagerInterface $objectManagerInterface) { $this->_configFactory = $configFactory->create(); $this->_objectManager = $objectManagerInterface; }
public function __construct(\Magento\Eav\Model\ConfigFactory $configFactory, \Magento\SalesRule\Model\Rule\Condition\ProductFactory $productFactory, \Magento\Framework\ObjectManagerInterface $objectManagerInterface) { $this->_configFactory = $configFactory->create(); $this->_objectManager = $objectManagerInterface; $this->_productFactory = $productFactory->create(); }