/** * Get warning messages to display during the mass edit action * @param ProductInterface[] $products * * @return string[] */ protected function generateWarningMessages(array $products) { $messages = []; $variantAttributeCodes = $this->massActionManager->getCommonAttributeCodesInVariant($products); $rootMessageKey = 'pim_enrich.mass_edit_action.edit-common-attributes'; if (count($variantAttributeCodes) > 0) { $messages[] = ['key' => $rootMessageKey . '.truncated_by_variant_attribute.warning', 'options' => ['%attributes%' => implode(', ', $variantAttributeCodes)]]; } if (count($this->getCommonAttributes()) < 1) { $messages[] = ['key' => $rootMessageKey . '.no_attribute.warning', 'options' => []]; } return $messages; }
/** * Initializes self::commonAtributes with values from the repository * Attribute is not available for mass editing if: * - it is an identifier * - it is unique * - without value AND not link to family * - is not common to every products * * @param array $productIds */ protected function initializeCommonAttributes(array $productIds) { // Set attribute options locale $currentLocaleCode = $this->getLocale()->getCode(); $this->catalogContext->setLocaleCode($currentLocaleCode); // Get common attributes $attributes = $this->massActionManager->findCommonAttributes($productIds); foreach ($attributes as $attribute) { $attribute->setLocale($currentLocaleCode); $attribute->getGroup()->setLocale($currentLocaleCode); $this->commonAttributes[] = $attribute; } }
/** * Initializes self::allAtributes with values from the repository * * @return array */ public function getAllAttributes() { if (null === $this->allAttributes) { $locale = $this->getLocale()->getCode(); $allAttributes = $this->attributeRepository->findWithGroups([], ['conditions' => ['unique' => 0]]); foreach ($allAttributes as $attribute) { $attribute->setLocale($locale); $attribute->getGroup()->setLocale($locale); } $allAttributes = $this->massActionManager->filterLocaleSpecificAttributes($allAttributes, $locale); $this->allAttributes = $allAttributes; } return $this->allAttributes; }