Jump to content

problem with direct download virtual product (file) in the email


Recommended Posts

hey, i have a shop in prestashop to articles for students...
and i want that when the credit card payment recived the file will be automatic send to the costumer, i dont whant that the file will be ready to download in "my orders" page...

aftger i recived the email with the sentence:

"Below are direct links to these products: {virtualProducts} "


the words {virtualProducts} is not a link and i cant download anything...

thx

Link to comment
Share on other sites

i look in the download_product html page and i see that there is no link in the sentence:
Below are direct links to these products: {virtualProducts}
the words {virtualProducts} are not link to anywhere...
maybe i need to add a link command?

Link to comment
Share on other sites

{virtualProducts} is supposed to be replaced with direct links to the downloadable products. Did you click the "Is this a downloadable product?" checkbox on the product editor and upload the document to the product? It is the addWithemail function in classes/OrderHistory.php that send the "Virtual product to download" email.

Link to comment
Share on other sites

i did the attachment file (i see the download file in the my order page).
in the OrderHistory.php this is my code:

  public function addWithemail($autodate = true, $templateVars = false)
   {
       if (!parent::add($autodate))
           return false;

       $lastOrderState = $this->getLastOrderState($this->id_order);

       $result = Db::getInstance()->getRow('
           SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`
           FROM `'._DB_PREFIX_.'order_history` oh
               LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
               LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
               LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
               LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
           WHERE oh.`id_order_history` = '.intval($this->id).'
               AND os.`send_email` = 1');

       if (isset($result['template']) AND Validate::isEmail($result['email']))
       {
           $topic = $result['osname'];
           $data = array('{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => intval($this->id_order));
           if ($templateVars) $data = array_merge($data, $templateVars);
           $order = new Order(intval($this->id_order));
           $data['{total_paid}'] = Tools::displayPrice(floatval($order->total_paid), new Currency(intval($order->id_currency)), false, false);
           $data['{order_name}'] = sprintf("#d", intval($order->id));
           // additionnal links for download virtual product
           if ($virtualProducts = $order->getVirtualProducts() AND $this->id_order_state==_PS_OS_PAYMENT_)
           {
               global $smarty;
               $display = '';
               $assign = array();
               foreach ($virtualProducts AS $key => $virtualProduct)
               {
                   $id_product_download = ProductDownload::getIdFromIdProduct($virtualProduct['product_id']);
                   $product_download = new ProductDownload($id_product_download);
                   $assign[$key]['name'] = $product_download->display_filename;
                   $assign[$key]['link'] = $product_download->getTextLink(false, $virtualProduct['download_hash']);
                   if ($virtualProduct['download_deadline'] != '0000-00-00 00:00:00')
                       $assign[$key]['deadline'] = Tools::displayDate($virtualProduct['download_deadline'], $order->id_lang);
                   if ($product_download->nb_downloadable != 0)
                       $assign[$key]['downloadable'] = $product_download->nb_downloadable;
               }
               $smarty->assign('virtualProducts', $assign);
               $iso = Language::getIsoById(intval($order->id_lang));
               $links = $smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
               $tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
               $data = array_merge ($data, $tmpArray);
               global $_LANGMAIL;
               $subject = 'Virtual product to download';
               Mail::Send(intval($order->id_lang), 'download_product', ((is_array($_LANGMAIL) AND key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject), $data, $result['email'], $result['firstname'].' '.$result['lastname']);
           }

           if (Validate::isLoadedObject($order))
               Mail::Send(intval($order->id_lang), $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname']);
       }

       if ($lastOrderState->id !== $this->id_order_state)
           Hook::postUpdateOrderStatus($this->id_order_state, intval($this->id_order));
       return true;
   }

Link to comment
Share on other sites

So you added the document as an attachment rather than a downloadable product? That's why the "Virtual product to download" email isn't being sent. Attachment can be downloaded for free from the "Download" tab on the product page. Downloadable products must be purchased before they can be downloaded. Unless you want students to download your documents for free, you should remove them as attachments and add them as downloadable products.

Link to comment
Share on other sites

what is the Differences Between: "attachments" and "downloadable products"..
when i add a product i check the "Is this a downloadable product?" and then i upload the file..

i cant download anything because the words {virtualProducts} in my mail is not a link and i dont get ant direct link to download the file....

Link to comment
Share on other sites

Attachments can be downloaded for free from the Download tab at the bottom of the product page. You could use attachments to add a free manual for a product. Links to attachments do not appear in the email sent to the customer. Downloadable products are only accessible after you have paid for them. Links to the downloadable products are sent in an email to the customer after they have purchased the product. The text {virtualProducts} in the email template is replaced with these links when the email is sent to the customer.

Link to comment
Share on other sites

So when you try buying a downloadable product, the "Virtual product to download" email sent to your index has {virtualProducts} instead of the links? Check to make sure that download_product.tpl exists in the mails directory in every iso directory.

Link to comment
Share on other sites

I mean make sure that there is one in mails/en, mails/fr, mails/es and any other languages you have installed. If that doesn't work, I'm stumped. Looking at the code, the "Virtual products to download" email can't be sent unless the $virtualProducts variable is not NULL. I suggest that you add a debugging line like this after the if ($virtualProducts = ...) { on line 137 of classes/OrderHistory.php to see what is in the variable:

var_dump($virtualProducts);
die();



When you do a test order with downloadable products, this will stop executing before sending the email and display the contents of the $virtualProducts variable. If that looks fine, try adding a line after $links = ... on line 155 and add debugging code after it:

die($links);



This will display the text that {virtualProducts} will be replaced with.

Link to comment
Share on other sites

i am not sure where to put the debugging code, i try to put it after { but nothing happend and i am getting the same mail..
this is the code from OrderHistory.php, where i need to put the debugging code:

if ($virtualProducts = $order->getVirtualProducts() AND $this->id_order_state==_PS_OS_PAYMENT_)
           {
               global $smarty;
               $display = '';
               $assign = array();
               foreach ($virtualProducts AS $key => $virtualProduct)
               {
                   $id_product_download = ProductDownload::getIdFromIdProduct($virtualProduct['product_id']);
                   $product_download = new ProductDownload($id_product_download);
                   $assign[$key]['name'] = $product_download->display_filename;
                   $assign[$key]['link'] = $product_download->getTextLink(false, $virtualProduct['download_hash']);
                   if ($virtualProduct['download_deadline'] != '0000-00-00 00:00:00')
                       $assign[$key]['deadline'] = Tools::displayDate($virtualProduct['download_deadline'], $order->id_lang);
                   if ($product_download->nb_downloadable != 0)
                       $assign[$key]['downloadable'] = $product_download->nb_downloadable;
               }
               $smarty->assign('virtualProducts', $assign);
               $iso = Language::getIsoById(intval($order->id_lang));
               $links = $smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
               $tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
               $data = array_merge ($data, $tmpArray);
               global $_LANGMAIL;
               $subject = 'Virtual product to download';
               Mail::Send(intval($order->id_lang), 'download_product', ((is_array($_LANGMAIL) AND key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject), $data, $result['email'], $result['firstname'].' '.$result['lastname']);
           }

           if (Validate::isLoadedObject($order))
               Mail::Send(intval($order->id_lang), $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname']);
       }

       if ($lastOrderState->id !== $this->id_order_state)
           Hook::postUpdateOrderStatus($this->id_order_state, intval($this->id_order));
       return true;
   }

   public function isValidated()
   {
       return Db::getInstance()->getValue('
       SELECT COUNT(oh.`id_order_history`) AS nb
       FROM `'._DB_PREFIX_.'order_state` os 
       LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (os.`id_order_state` = oh.`id_order_state`) 
       WHERE oh.`id_order` = '.intval($this->id_order).'
       AND os.`logable` = 1
       ');
   }

}

?>



i forget to tell you that the order process is in SSL mode, maybe its away to solution?

Link to comment
Share on other sites

Try changing the top lines to:

if ($virtualProducts = $order->getVirtualProducts() AND $this->id_order_state==_PS_OS_PAYMENT_)
{
               global $smarty;
               var_dump($virtualProducts);
               $display = '';
               $assign = array();
               foreach ($virtualProducts AS $key => $virtualProduct)
               {
                   $id_product_download = ProductDownload::getIdFromIdProduct($virtualProduct['product_id']);
                   $product_download = new ProductDownload($id_product_download);
                   $assign[$key]['name'] = $product_download->display_filename;
                   $assign[$key]['link'] = $product_download->getTextLink(false, $virtualProduct['download_hash']);
                   if ($virtualProduct['download_deadline'] != '0000-00-00 00:00:00')
                       $assign[$key]['deadline'] = Tools::displayDate($virtualProduct['download_deadline'], $order->id_lang);
                   if ($product_download->nb_downloadable != 0)
                       $assign[$key]['downloadable'] = $product_download->nb_downloadable;
               }
               $smarty->assign('virtualProducts', $assign);
               $iso = Language::getIsoById(intval($order->id_lang));
               $links = $smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
               die('
{virtualProducts} is ' . $links);

Link to comment
Share on other sites

No email should have been sent at all. You should have gotten output instead. What was the output? You aren't expecting the text in the email template to change from {virtualProducts} to direct links are you? The email templates themselves never change.

  • Like 1
Link to comment
Share on other sites

when i got the order message in the back office panel i choose the option that send to the client email with the download link and after that go to the mail and see the download page mail (witout any link). the email never send to me automatic, i am always send it via the back office panel in the order page...
where i should see the output message? in my mail? it is send automatic?.
i expect to see direct link to download my file in the email, Is not that so?

Link to comment
Share on other sites

ok, i try to explain.
the idie is, to allowed (permit) download the file only after the payment recived and Success. (i am using a offline credit card module and i need to make the payment in manuel) so only if the payment was Success i choose in back office -> Order Messages the option "send file to client" ( i maked this option in the "Statuses" page and checked the option "Send e-mail client with a different arrangement in this situation" and in the template option i did the "download_product" option ).
so after the payment succefull i choose this option in the "order page", and then.. the email send to me..

Link to comment
Share on other sites

That's the way PrestaShop is set up by default when you tick "Is this a downloadable product" and upload a product. I do it on my website, since I sell a PrestaShop module and it works perfectly for me. I don't understand why it isn't working for you.

I don't need to go to the Orders > Messages tab to send my file. A link to the file just gets automatically emailed to the customer once the PayPal payment is completed, so I don't have do anything when I receive an order.

Link to comment
Share on other sites

  • 2 years later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...