Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<services>
<service id="virtualproductdelivery.events" class="VirtualProductDelivery\EventListeners\VirtualProductEvents">
<tag name="kernel.event_subscriber"/>
</service>
<service id="virtualproductdelivery.mail" class="VirtualProductDelivery\EventListeners\SendMail">
<argument type="service" id="mailer"/>
<argument type="service" id="event_dispatcher"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
<hooks>
<hook id="virtualproductdelivery.hook" class="VirtualProductDelivery\Hook\HookManager">
<tag name="hook.event_listener" event="order-invoice.delivery-address" type="front" templates="render:delivery-address.html" />
<tag name="hook.event_listener" event="account-order.after-products" type="front"/>
<tag name="hook.event_listener" event="delivery.delivery-address" type="pdf" templates="render:delivery-address.html" />
<tag name="hook.event_listener" event="invoice.delivery-address" type="pdf" templates="render:delivery-address.html" />
</hook>
</hooks>
</config>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
<fullnamespace>VirtualProductDelivery\VirtualProductDelivery</fullnamespace>
<descriptive locale="en_US">
<title>Virtual Products Delivery</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Livraison Produits Virtuels</title>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.3.5</version>
<author>
<name>Julien Chanséaume</name>
<email>jchanseaume@openstudio.fr</email>
</author>
<type>delivery</type>
<thelia>2.2.0</thelia>
<stability>alpha</stability>
</module>

View File

@@ -0,0 +1,122 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace VirtualProductDelivery\EventListeners;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Log\Tlog;
use Thelia\Mailer\MailerFactory;
use Thelia\Model\OrderProductQuery;
use VirtualProductDelivery\Events\VirtualProductDeliveryEvents;
/**
* Class SendMail
* @package VirtualProductDelivery\EventListeners
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class SendMail implements EventSubscriberInterface
{
/** @var MailerFactory */
protected $mailer;
/** @var EventDispatcherInterface */
protected $eventDispatcher;
public function __construct(MailerFactory $mailer, EventDispatcherInterface $eventDispatcher)
{
$this->mailer = $mailer;
$this->eventDispatcher = $eventDispatcher;
}
public function updateStatus(OrderEvent $event)
{
$order = $event->getOrder();
if ($order->hasVirtualProduct() && $order->isPaid(true)) {
$this->eventDispatcher->dispatch(
VirtualProductDeliveryEvents::ORDER_VIRTUAL_FILES_AVAILABLE,
$event
);
}
}
/**
* Send email to notify customer that files for virtual products are available
*
* @param OrderEvent $event
* @throws \Exception
*/
public function sendEmail(OrderEvent $event)
{
$order = $event->getOrder();
// Be sure that we have a document to download
$virtualProductCount = OrderProductQuery::create()
->filterByOrderId($order->getId())
->filterByVirtual(true)
->filterByVirtualDocument(null, Criteria::NOT_EQUAL)
->count();
if ($virtualProductCount > 0) {
$customer = $order->getCustomer();
$this->mailer->sendEmailToCustomer(
'mail_virtualproduct',
$customer,
[
'customer_id' => $customer->getId(),
'order_id' => $order->getId(),
'order_ref' => $order->getRef(),
'order_date' => $order->getCreatedAt(),
'update_date' => $order->getUpdatedAt()
]
);
} else {
Tlog::getInstance()->warning(
"Virtual product download message not sent to customer: there's nothing to downnload"
);
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128),
VirtualProductDeliveryEvents::ORDER_VIRTUAL_FILES_AVAILABLE => array("sendEmail", 128)
);
}
}

View File

@@ -0,0 +1,119 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace VirtualProductDelivery\EventListeners;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Thelia\Core\Event\Product\VirtualProductOrderDownloadResponseEvent;
use Thelia\Core\Event\Product\VirtualProductOrderHandleEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
use Thelia\Model\MetaDataQuery;
use Thelia\Model\MetaData as MetaDataModel;
use Thelia\Model\ProductDocumentQuery;
use VirtualProductDelivery\VirtualProductDelivery;
/**
* Class VirtualProductEvents
* @package VirtualProductDelivery\EventListeners
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class VirtualProductEvents implements EventSubscriberInterface
{
public function handleOrder(VirtualProductOrderHandleEvent $event)
{
$documentId = MetaDataQuery::getVal(
'virtual',
MetaDataModel::PSE_KEY,
$event->getPseId()
);
if (null !== $documentId) {
$productDocument = ProductDocumentQuery::create()->findPk($documentId);
if (null !== $productDocument) {
$event->setPath($productDocument->getFile());
}
}
}
public function download(VirtualProductOrderDownloadResponseEvent $event)
{
$orderProduct = $event->getOrderProduct();
if ($orderProduct->getVirtualDocument()) {
$baseSourceFilePath = ConfigQuery::read('documents_library_path');
if ($baseSourceFilePath === null) {
$baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'documents';
} else {
$baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
}
// try to get the file
$path = $baseSourceFilePath . DS . 'product' . DS . $orderProduct->getVirtualDocument();
if (!is_file($path) || !is_readable($path)) {
throw new \ErrorException(
Translator::getInstance()->trans(
"The file [%file] does not exist",
[
"%file" => $orderProduct->getId()
],
VirtualProductDelivery::MESSAGE_DOMAIN
)
);
}
$response = new BinaryFileResponse($path);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
$event->setResponse($response);
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return [
TheliaEvents::VIRTUAL_PRODUCT_ORDER_HANDLE => ['handleOrder', 128],
TheliaEvents::VIRTUAL_PRODUCT_ORDER_DOWNLOAD_RESPONSE => ['download', 128]
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace VirtualProductDelivery\Events;
use Thelia\Core\Event\ActionEvent;
/**
* Class VirtualProductDeliveryEvents
* @package VirtualProductDelivery\Events
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class VirtualProductDeliveryEvents extends ActionEvent
{
const ORDER_VIRTUAL_FILES_AVAILABLE = 'virtual_product_delivery.virtual_files_available';
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace VirtualProductDelivery\Hook;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
/**
* Class HookManager
* @package VirtualProductDelivery\Hook
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class HookManager extends BaseHook
{
public function onAccountOrderAfterProducts(HookRenderEvent $event)
{
$orderId = $event->getArgument('order');
if (null !== $orderId) {
$render = $this->render(
'account-order-after-products.html',
[
"order_id" => $orderId
]
);
$event->add($render);
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
return [
'Order {$order_ref} validated. Download your files.' => 'Bestellung {$order_ref} validiert. Laden Sie Ihre Dateien herunter.',
'The file [%file] does not exist' => 'Die Datei [%file] existiert nicht',
'This module cannot be used on the current cart.' => 'Dieses Modul kann nicht für diesen Warenkorb benutzt werden. ',
'Virtual product download message' => 'Virtuelles Produkt Herunterladung Nachricht',
];

View File

@@ -0,0 +1,10 @@
<?php
return array(
'Best Regards.' => 'Best Regards.',
'Feel free to contact us for any further information.' => 'Feel free to contact us for any further information.',
'Products:' => 'Products:',
'You have to be logged in to your account to download this files.' => 'You have to be logged in to your account to download this files.',
'Your order %ref has been validated. You can download your files.' => 'Your order %ref has been validated. You can download your files.',
'have to be logged in to your account to download this files.' => 'have to be logged in to your account to download this files.',
);

View File

@@ -0,0 +1,10 @@
<?php
return [
'Best Regards.' => 'Cordialement',
'Feel free to contact us for any further information.' => 'N\'hésitez pas à nous contacter pour toute information complémentaire.',
'Products:' => 'Articles à télécharger:',
'You have to be logged in to your account to download this files.' => 'Vous devez être connecté à votre compte pour pouvoir télécharger le fichier.',
'Your order %ref has been validated. You can download your files.' => 'Votre commande %ref a été validé. Vous pouvez désormais télécharger vos fichiers.',
'have to be logged in to your account to download this files.' => 'Vous devez être connecté à votre compte pour pouvoir télécharger les fichiers.',
];

View File

@@ -0,0 +1,10 @@
<?php
return [
'Best Regards.' => 'Distinti saluti.',
'Feel free to contact us for any further information.' => 'Non esitate a contattarci per qualsiasi ulteriore informazione.',
'Products:' => 'Prodotti:',
'You have to be logged in to your account to download this files.' => 'Devi essere loggato al tuo account per poter scaricare questi file.',
'Your order %ref has been validated. You can download your files.' => 'Il vostro ordine %ref è stato convalidato. È possibile scaricare i file.',
'have to be logged in to your account to download this files.' => 'devi essere loggato al tuo account per poter scaricare questi file.',
];

View File

@@ -0,0 +1,10 @@
<?php
return [
'Best Regards.' => 'Saygılarımızla,.',
'Feel free to contact us for any further information.' => 'Daha fazla bilgi için bizimle temas kurmaktan çekinmeyin.',
'Products:' => 'ürün:',
'You have to be logged in to your account to download this files.' => 'Bu dosyaları karşıdan yüklemek için hesabınıza oturum açmış olmanız gerekir.',
'Your order %ref has been validated. You can download your files.' => 'Sipariş %ref doğrulandı. Sen-ebilmek download senin eğe.',
'have to be logged in to your account to download this files.' => 'Bu dosyaları karşıdan yüklemek için hesabınıza oturum açmış olmanız gerekir.',
];

View File

@@ -0,0 +1,8 @@
<?php
return array(
'Order {$order_ref} validated. Download your files.' => 'Order {$order_ref} validated. Download your files.',
'The file [%file] does not exist' => 'The file [%file] does not exist',
'This module cannot be used on the current cart.' => 'This module cannot be used on the current cart.',
'Virtual product download message' => 'Virtual product download message',
);

View File

@@ -0,0 +1,8 @@
<?php
return [
'Order {$order_ref} validated. Download your files.' => 'Commande {$order_ref} validée. Téléchargez vos fichiers.',
'The file [%file] does not exist' => 'le fichier [%file] n\'existe pas',
'This module cannot be used on the current cart.' => 'Ce module ne peut pas être utilisé avec le panier actuel.',
'Virtual product download message' => 'Message pour le téléchargement des produits virtuels',
];

View File

@@ -0,0 +1,9 @@
<?php
return [
'Delivery address' => 'Lieferadresse',
'Download' => 'Herunterladen',
'File' => 'Datei',
'List of downloadable files' => 'Liste der herunterladbaren Dateien',
'No delivery address for this delivery method' => 'Keine Lieferadresse für diese Liefermethode',
];

View File

@@ -0,0 +1,9 @@
<?php
return array(
'Delivery address' => 'Delivery address',
'Download' => 'Download',
'File' => 'File',
'List of downloadable files' => 'List of downloadable files',
'No delivery address for this delivery method' => 'No delivery address for this delivery method',
);

View File

@@ -0,0 +1,9 @@
<?php
return [
'Delivery address' => 'Adresse de livraison',
'Download' => 'Télécharger',
'File' => 'Fichier',
'List of downloadable files' => 'Liste des fichiers téléchargeables',
'No delivery address for this delivery method' => 'L\'adresse de livraison n\'est pas nécessaire pour cette méthode de livraison',
];

View File

@@ -0,0 +1,8 @@
<?php
return [
'Delivery address' => 'Indirizzo di consegna',
'File' => 'File',
'List of downloadable files' => 'Elenco dei file scaricabili',
'No delivery address for this delivery method' => 'Nessun indirizzo di consegna per questo metodo di consegna',
];

View File

@@ -0,0 +1,9 @@
<?php
return [
'Delivery address' => 'Teslimat adresi',
'Download' => 'İndir',
'File' => 'Dosya',
'List of downloadable files' => 'İndirilebilir dosyalar',
'No delivery address for this delivery method' => 'Bu teslim yöntemi için hiçbir teslimat adresi',
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'Order {$order_ref} validated. Download your files.' => 'Ordine {$order_ref} convalidato. Scarica i tuoi file.',
'The file [%file] does not exist' => 'Il file [%file] non esiste',
'This module cannot be used on the current cart.' => 'Questo modulo non può essere utilizzato sul carrello attuale.',
];

View File

@@ -0,0 +1,5 @@
<?php
return [
'No delivery address for this delivery method' => 'Keine Lieferadresse für diese Liefermethode',
];

View File

@@ -0,0 +1,5 @@
<?php
return array(
'No delivery address for this delivery method' => 'No delivery address for this delivery method',
);

View File

@@ -0,0 +1,5 @@
<?php
return [
'No delivery address for this delivery method' => 'L\'adresse de livraison n\'est pas nécessaire pour cette méthode de livraison',
];

View File

@@ -0,0 +1,5 @@
<?php
return [
'No delivery address for this delivery method' => 'Nessun indirizzo di consegna per questo metodo di consegna',
];

View File

@@ -0,0 +1,5 @@
<?php
return [
'No delivery address for this delivery method' => 'Bu teslim yöntemi için hiçbir teslimat adresi',
];

View File

@@ -0,0 +1,8 @@
<?php
return [
'Order {$order_ref} validated. Download your files.' => 'Doğrulanmış {$order_ref} sipariş. Download senin eğe.',
'The file [%file] does not exist' => '[%file] dosyası yok',
'This module cannot be used on the current cart.' => 'Bu modül geçerli arabaya kullanılamaz.',
'Virtual product download message' => 'Sanal ürün indir mesaj',
];

View File

@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@@ -0,0 +1,105 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace VirtualProductDelivery;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Country;
use Thelia\Model\LangQuery;
use Thelia\Model\Message;
use Thelia\Model\MessageQuery;
use Thelia\Module\AbstractDeliveryModule;
use Thelia\Module\Exception\DeliveryException;
class VirtualProductDelivery extends AbstractDeliveryModule
{
const MESSAGE_DOMAIN = 'virtualproductdelivery';
/** @var Translator */
protected $translator;
/**
* The module is valid if the cart contains only virtual products.
*
* @param Country $country
*
* @return bool true if there is only virtual products in cart elsewhere false
*/
public function isValidDelivery(Country $country)
{
return $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->isVirtual();
}
public function getPostage(Country $country)
{
if (!$this->isValidDelivery($country)) {
throw new DeliveryException(
$this->trans("This module cannot be used on the current cart.")
);
}
return 0.0;
}
/**
* This module manages virtual product delivery
*
* @return bool
*/
public function handleVirtualProductDelivery()
{
return true;
}
public function postActivation(ConnectionInterface $con = null)
{
// create new message
if (null === MessageQuery::create()->findOneByName('mail_virtualproduct')) {
$message = new Message();
$message
->setName('mail_virtualproduct')
->setHtmlTemplateFileName('virtual-product-download.html')
->setHtmlLayoutFileName('')
->setTextTemplateFileName('virtual-product-download.txt')
->setTextLayoutFileName('')
->setSecured(0);
$languages = LangQuery::create()->find();
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setSubject(
$this->trans('Order {$order_ref} validated. Download your files.', [], $locale)
);
$message->setTitle(
$this->trans('Virtual product download message', [], $locale)
);
}
$message->save();
}
}
protected function trans($id, $parameters = [], $locale = null)
{
if (null === $this->translator) {
$this->translator = Translator::getInstance();
}
return $this->translator->trans($id, $parameters, self::MESSAGE_DOMAIN, $locale);
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "thelia/virtual-product-delivery-module",
"license": "LGPL-3.0+",
"type": "thelia-module",
"require": {
"thelia/installer": "~1.1"
},
"extra": {
"installer-name": "VirtualProductDelivery"
}
}

View File

@@ -0,0 +1,29 @@
{default_translation_domain domain="virtualproductdelivery.email.default"}
{default_locale locale={$locale}}
{loop name="order.invoice" type="order" id=$order_id customer="*" limit="1" backend_context="1"}
<p>
{intl l="Your order %ref has been validated. You can download your files." ref={$REF}}</p>
<p>{intl l="Products:"}</p>
<ul>
{loop type="order_product" name="order-products" order=$ID virtual="1" backend_context="1"}
<li>
{$TITLE} : <a href="{url path="/account/download/$ID"}">{url path="/account/download/$ID"}</a>
{ifloop rel="combinations"}
<br><em>
{loop type="order_product_attribute_combination" name="combinations" order_product=$ID}
{$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}
{/loop}</em>
{/ifloop}
</li>
{/loop}
</ul>
{/loop}
<p>{intl l="You have to be logged in to your account to download this files."}</p>
<p>{intl l="Feel free to contact us for any further information."}</p>
<p>{intl l="Best Regards."}</p>

View File

@@ -0,0 +1,26 @@
{default_translation_domain domain="virtualproductdelivery.email.default"}
{default_locale locale={$locale}}
{loop name="order.invoice" type="order" id=$order_id customer="*" limit="1" backend_context="1"}
{intl l="Your order %ref has been validated. You can download your files." ref={$REF}}
----------------------------------------------------------------------
{intl l="Products:"}
----------------------------------------------------------------------
{loop type="order_product" name="order-products" order=$ID virtual="1" backend_context="1"}
{$TITLE} : {url path="/account/download/$ID"}
{ifloop rel="combinations"}
{loop type="order_product_attribute_combination" name="combinations" order_product=$ID}
{$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}
{/loop}
{/ifloop}
----------------------------------------------------------------------
{/loop}
{/loop}
{intl l="You have to be logged in to your account to download this files."}
{intl l="Feel free to contact us for any further information."}
{intl l="Best Regards."}

View File

@@ -0,0 +1,24 @@
{loop type="order" name="virtual.order" id="$order_id" limit="1"}
{if $STATUS >=2 && $VIRTUAL}
<table class="table table-condensed table-order" summary="{intl l="List of downloadable files" d='virtualproductdelivery.fo.default'}">
<thead>
<tr>
<th>{intl l="File" d='virtualproductdelivery.fo.default'}</th>
<th>{intl l="Download" d='virtualproductdelivery.fo.default'}</th>
</tr>
</thead>
<tbody>
{loop name="virtual.order.products" type="order_product" virtual="1" order={$ID}}
<tr>
<td>{$TITLE}</td>
<td>
<a href="{url path="/account/download/$ID"}" class="btn">
<span class="glyphicon glyphicon-download"></span> {intl l="Download" d='virtualproductdelivery.fo.default'}
</a>
</td>
</tr>
{/loop}
</tbody>
</table>
{/if}
{/loop}

View File

@@ -0,0 +1,6 @@
<div class="panel">
<div class="panel-heading">{intl l="Delivery address" d="virtualproductdelivery.fo.default"}</div>
<div class="panel-body">
{intl l="No delivery address for this delivery method" d="virtualproductdelivery.fo.default"}
</div>
</div>

View File

@@ -0,0 +1,3 @@
<p>
{intl l="No delivery address for this delivery method" d="virtualproductdelivery.pdf.default"}
</p>