Model/Connector/Product.php
public function setProduct($product)
    {
        $this->id = $product->getId();
        $this->sku = $product->getSku();
        $this->name = $product->getName();

        $this->status = $this->statusFactory->create()
            ->getOptionText($product->getStatus());

        $options = $this->visibilityFactory->create()
            ->getOptionArray();
        $this->visibility = (string)$options[$product->getVisibility()];

        $this->getMinPrices($product);

        $this->url = $this->urlFinder->fetchFor($product);

        $this->imagePath = $this->mediaConfigFactory->create()
            ->getMediaUrl($product->getSmallImage());

        $this->stock = (float)number_format($this->getStockQty($product), 2, '.', '');

        $shortDescription = $product->getShortDescription();
        //limit short description
        if ($this->stringUtils->strlen($shortDescription) > \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT) {
            $shortDescription = mb_substr($shortDescription, 0, \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT);
        }

        $this->shortDescription = $shortDescription;

        //category data
        $count = 0;
        $categoryCollection = $product->getCategoryCollection()
            ->addNameToResult();
        foreach ($categoryCollection as $cat) {
            $this->categories[$count]['Id'] = $cat->getId();
            $this->categories[$count]['Name'] = $cat->getName();
            ++$count;
        }

        //website data
        $count = 0;
        $websiteIds = $product->getWebsiteIds();
        foreach ($websiteIds as $websiteId) {
            $website = $this->storeManager->getWebsite(
                $websiteId
            );
            $this->websites[$count]['Id'] = $website->getId();
            $this->websites[$count]['Name'] = $website->getName();
            ++$count;
        }

        $this->processProductOptions($product);

        unset(
            $this->itemFactory,
            $this->mediaConfigFactory,
            $this->visibilityFactory,
            $this->statusFactory,
            $this->helper,
            $this->storeManager
        );

        return $this;
    }
public function setProduct($product)
    {
        $this->id = $product->getId();
        $this->sku = $product->getSku();
        $this->name = $product->getName();

        $this->status = $this->statusFactory->create()
            ->getOptionText($product->getStatus());

        $options = $this->visibilityFactory->create()
            ->getOptionArray();
        $this->visibility = (string)$options[$product->getVisibility()];

        $this->getMinPrices($product);

        $this->url = $this->urlFinder->fetchFor($product);

        $this->imagePath = $this->mediaConfigFactory->create()
            ->getMediaUrl($product->getSmallImage());

        $this->stock = (float)number_format($this->getStockQty($product), 2, '.', '');

        $shortDescription = $product->getShortDescription();
        //limit short description
        if ($this->stringUtils->strlen($shortDescription) > \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT) {
            $shortDescription = mb_substr($shortDescription, 0, \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT);
        }

        $this->shortDescription = $shortDescription;

        //category data
        $count = 0;
        $categoryCollection = $product->getCategoryCollection()
            ->addNameToResult();
        foreach ($categoryCollection as $cat) {
            $this->categories[$count]['Id'] = $cat->getId();
            $this->categories[$count]['Name'] = $cat->getName();
            ++$count;
        }

        //website data
        $count = 0;
        $websiteIds = $product->getWebsiteIds();
        foreach ($websiteIds as $websiteId) {
            $website = $this->storeManager->getWebsite(
                $websiteId
            );
            $this->websites[$count]['Id'] = $website->getId();
            $this->websites[$count]['Name'] = $website->getName();
            ++$count;
        }

        $this->processProductOptions($product);

        unset(
            $this->itemFactory,
            $this->mediaConfigFactory,
            $this->visibilityFactory,
            $this->statusFactory,
            $this->helper,
            $this->storeManager
        );

        return $this;
    }
public function setProduct ( $ product ) { $ this -> id = $ product -> getId ( ) ; $ this -> sku = $ product -> getSku ( ) ; $ this -> name = $ product -> getName ( ) ; $ this -> status = $ this -> statusFactory -> create ( ) -> getOptionText ( $ product -> getStatus ( ) ) ; $ options = $ this -> visibilityFactory -> create ( ) -> getOptionArray ( ) ; $ this -> visibility = ( string ) $ options [ $ product -> getVisibility ( ) ] ; $ this -> getMinPrices ( $ product ) ; $ this -> url = $ this -> urlFinder -> fetchFor ( $ product ) ; $ this -> imagePath = $ this -> mediaConfigFactory -> create ( ) -> getMediaUrl ( $ product -> getSmallImage ( ) ) ; $ this -> stock = ( float ) number_format ( $ this -> getStockQty ( $ product ) , 2 , '.' , '' ) ; $ shortDescription = $ product -> getShortDescription ( ) ; //limit short description if ( $ this -> stringUtils -> strlen ( $ shortDescription ) > \ Dotdigitalgroup \ Email \ Helper \ Data :: DM_FIELD_LIMIT ) { $ shortDescription = mb_substr ( $ shortDescription , 0 , \ Dotdigitalgroup \ Email \ Helper \ Data :: DM_FIELD_LIMIT ) ; } $ this -> shortDescription = $ shortDescription ; //category data $ count = 0 ; $ categoryCollection = $ product -> getCategoryCollection ( ) -> addNameToResult ( ) ; foreach ( $ categoryCollection as $ cat ) { $ this -> categories [ $ count ] [ 'Id' ] = $ cat -> getId ( ) ; $ this -> categories [ $ count ] [ 'Name' ] = $ cat -> getName ( ) ; ++ $ count ; } //website data $ count = 0 ; $ websiteIds = $ product -> getWebsiteIds ( ) ; foreach ( $ websiteIds as $ websiteId ) { $ website = $ this -> storeManager -> getWebsite ( $ websiteId ) ; $ this -> websites [ $ count ] [ 'Id' ] = $ website -> getId ( ) ; $ this -> websites [ $ count ] [ 'Name' ] = $ website -> getName ( ) ; ++ $ count ; } $ this -> processProductOptions ( $ product ) ; unset ( $ this -> itemFactory , $ this -> mediaConfigFactory , $ this -> visibilityFactory , $ this -> statusFactory , $ this -> helper , $ this -> storeManager ) ; return $ this ; }
Set the product data.

@param \Magento\Catalog\Model\Product $product

@return $this
Set the product data .