1

How to get sample file url for a downloadable productenter image description here

  • 1
    what did you try so far? – fmsthird Apr 9 at 6:50
2

In Block Inject Downloadable Sample Collection

public function __construct(
        .....,
        .....,      
        \Magento\Downloadable\Model\ResourceModel\Sample\CollectionFactory $sampleCollectionFactory,
    ) {
        .....,
        .....,
       $this->_sampleCollectionFactory = $sampleCollectionFactory;
  }

   public function getSampleCollection($productId){
                     $collection = $this->_sampleCollectionFactory->create();
                     $collection->addProductToFilter($productId);
                     return $collection;
          }

In Phtml File

 $_mySampleCollection = $this->getSampleCollection(1); 
 foreach ($_mySampleCollection as $_sample): 
      {
       echo $_sample->getSampleUrl(); 
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.