0

Here i am trying to attach a dynamic link with every order in order email template. for eg:

<a href="pub/media/000001.pdf">Download Pdf</a>

And i have troied

<a href="{{media url="'{{var order.increment_id}}'.pdf"}}">Please download PDF</a>


<a href="{{media url="'{{%increment_id}}'.pdf"}}" download>Please download PDF</a>

and much more i cant get my exact url with Order id. Is there any way where i can attach a link with order id in pub media url. Small help will be greatly appreciated. Thanks in Advance :)

0

try this way

protected $_storeManager;
private $OrderFactory;


public function __construct(
    .........................................
    .........................................
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Sales\Model\OrderFactory $OrderFactory,
    .........................................
    .........................................
) {
    .........................................
    .........................................
    $this->_storeManager = $storeManager;
    $this->OrderFactory = $OrderFactory;
    .........................................
    .........................................
}

public function getOrderUrl($order_id)
{
    $order = $this->OrderFactory->create()->load($order_id);
    $link = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
    $link .=  $order->getIncrementId()."pdf";
    return $link;
}

in your email template

<a href="{{var order_url}}" target="_blank" download>

here order_url is your email tempate variable name which you pass into email template

| improve this answer | |
  • Please be more specifc where should i add this Php file – Sayyed Hasan Mar 12 at 10:27
  • add this into your email send code . for more please share your code your can call function by using $this->getOrderUrl($order_id); pass your order id in it. – Msquare Mar 12 at 10:30
  • I am not using any custom code i am just editing in Config Email Tempalte Marketing->Email Temp – Sayyed Hasan Mar 12 at 10:36
  • you have to pass value into Email Template. without pass value how you can do ? – Msquare Mar 12 at 10:41

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.