/** * Prepare Data Source * * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) { $dataSource = parent::prepareDataSource($dataSource); if (empty($dataSource['data']['items'])) { return $dataSource; } $fieldName = $this->getData('name'); $sourceFieldName = ProductInterface::STATUS; foreach ($dataSource['data']['items'] as &$item) { if (!empty($item[$sourceFieldName])) { $item[$fieldName] = $this->status->getOptionText($item[$sourceFieldName]); } } return $dataSource; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $modelId = $product->getId(); if ($modelId) { $storeId = $this->locator->getStore()->getId(); /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); $data[$product->getId()]['links'][self::LINK_TYPE] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== self::LINK_TYPE) { continue; } /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId); $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; } $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId; } return $data; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $productId = $product->getId(); if (!$productId) { return $data; } foreach ($this->getDataScopes() as $dataScope) { $data[$productId]['links'][$dataScope] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== $dataScope) { continue; } /** @var \Magento\Catalog\Model\Product $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId()); $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; } } $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId; $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId(); return $data; }
/** * Fill data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); return ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; }
/** * @dataProvider getOptionTextDataProvider * @param string $text * @param string $id */ public function testGetOptionText($text, $id) { $this->assertEquals($text, $this->status->getOptionText($id)); }
/** * Prepare data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { return ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; }