Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function getItemAttributes($type)
 {
     $output = [];
     $types = $this->getLinkTypes();
     $typeId = isset($types[$type]) ? $types[$type] : null;
     /** @var \Magento\Catalog\Model\Product\Link $link */
     $link = $this->linkFactory->create(['data' => ['link_type_id' => $typeId]]);
     $attributes = $link->getAttributes();
     foreach ($attributes as $item) {
         /** @var \Magento\Catalog\Api\Data\ProductLinkAttributeInterface $linkAttribute */
         $linkAttribute = $this->linkAttributeFactory->create();
         $linkAttribute->setCode($item['code'])->setType($item['type']);
         $output[] = $linkAttribute;
     }
     return $output;
 }
Пример #2
0
 /**
  * Get crosssell products collection
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection
  */
 protected function _getCollection()
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection $collection */
     $collection = $this->_productLinkFactory->create()->useCrossSellLinks()->getProductCollection()->setStoreId($this->_storeManager->getStore()->getId())->addStoreFilter()->setPageSize($this->_maxItemCount)->setVisibility($this->_productVisibility->getVisibleInCatalogIds());
     $this->_addProductAttributesAndPrices($collection);
     return $collection;
 }
Пример #3
0
 /**
  * Prepare collection
  *
  * @return \Magento\Backend\Block\Widget\Grid\Extended
  */
 protected function _prepareCollection()
 {
     $collection = $this->_linkFactory->create()->useUpSellLinks()->getProductCollection()->setProduct($this->getProduct())->addAttributeToSelect('*');
     if ($this->isReadonly()) {
         $productIds = $this->_getSelectedProducts();
         if (empty($productIds)) {
             $productIds = array(0);
         }
         $collection->addFieldToFilter('entity_id', array('in' => $productIds));
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function getLinkAttributes($type)
 {
     $output = [];
     $typeId = $this->linkTypeResolver->getTypeIdByCode($type);
     /** @var \Magento\Catalog\Model\Product\Link $link */
     $link = $this->linkFactory->create(['data' => ['link_type_id' => $typeId]]);
     $attributes = $link->getAttributes();
     foreach ($attributes as $item) {
         $data = [Data\LinkAttribute::CODE => $item['code'], Data\LinkAttribute::TYPE => $item['type']];
         $output[] = $this->linkAttributeBuilder->populateWithArray($data)->create();
     }
     return $output;
 }
Пример #5
0
 /**
  * Prepare collection
  *
  * @return Extended
  */
 protected function _prepareCollection()
 {
     /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection */
     $collection = $this->_linkFactory->create()->useCrossSellLinks()->getProductCollection()->setProduct($this->getProduct())->addAttributeToSelect('*');
     if ($this->isReadonly()) {
         $productIds = $this->_getSelectedProducts();
         if (empty($productIds)) {
             $productIds = [0];
         }
         $collection->addFieldToFilter('entity_id', ['in' => $productIds]);
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }