/** * @param $product * @return array */ public function getDefaultDrupalProduct(ProductInterface $product) { $labels = []; $attributeAsLabel = $product->getFamily()->getAttributeAsLabel(); $availableLocales = $attributeAsLabel->getAvailableLocales(); if (!is_null($availableLocales)) { foreach ($availableLocales as $availableLocale) { $labels[$availableLocale->getCode()] = $product->getLabel($availableLocale->getCode()); } } // TODO: fix availableLocales doesn t must be NULL foreach ($attributeAsLabel->getTranslations() as $translation) { $labels[$translation->getLocale()] = $product->getLabel($translation->getLocale()); } $defaultDrupalProduct = ['sku' => $product->getReference(), 'family' => $product->getFamily()->getCode(), 'created' => $product->getCreated()->format('c'), 'updated' => $product->getUpdated()->format('c'), 'status' => $product->isEnabled(), 'labels' => $labels, 'categories' => [], 'groups' => [], 'associations' => [], 'values' => []]; return $defaultDrupalProduct; }
/** * @param ProductInterface $product * * @return array */ protected function getLabels(ProductInterface $product) { $labels = []; foreach ($this->localeRepository->getActivatedLocaleCodes() as $localeCode) { $labels[$localeCode] = $product->getLabel($localeCode); } return ['label' => $labels]; }