Files
wyczarujprezent.pl/cron-dh2u37dhs7.php
2024-10-28 22:14:22 +01:00

118 lines
5.4 KiB
PHP

<?php
require(dirname(__FILE__).'/config/config.inc.php');
use PrestaShop\PrestaShop\Adapter\MailTemplate\MailPartialTemplateRenderer;
// download file
$context = Context::getContext();
$sql = "SELECT `id_order` FROM "._DB_PREFIX_."orders
WHERE (`issendemail` != 1 OR `issendemail` IS null) AND `current_state` = 16";
$orders = Db::getInstance()->executeS($sql);
$i = 0;
foreach ($orders as $order) {
$order = new Order($order['id_order']);
if($order) {
$products = $order->getCartProducts();
$customer = $order->getCustomer();
$products_links = array();
$context = Context::getContext();
foreach($products as $product) {
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config_product` where `id_cart` = ".$order->getCartIdStatic($order->id)." and `id_cart_product` = ".(int)$product['id_product']." and `id_customization` = ".(int)$product['id_customization'];
$configproduct = Db::getInstance()->getRow($q);
if($configproduct) {
$products_links[] = array(
'name' => $product['product_name'],
'url_pdf' => $context->link->getModuleLink('configurator', 'getpdf', array(
'token' => $configproduct['token']
)),
'url_config' => $context->link->getModuleLink('configurator', 'configureproduct', array(
'token' => $configproduct['token']
))
);
}
else if(!$configproduct) {
$obj = new Product((int)$product['id_product']);
if($obj->isconfigurable) {
$id_cart = $order->getCartIdStatic($order->id);
$cart = new Cart((int)$id_cart);
$bytes = random_bytes(20);
$token = bin2hex($bytes);
$sql = "INSERT INTO `" . _DB_PREFIX_ . "customization` (`id_product_attribute`, `id_address_delivery`, `id_cart`, `id_product`, `quantity`, `quantity_refunded`, `quantity_returned`, `in_cart`) VALUES
('".(int)$product['id_product_attribute']."','".$cart->id_address_delivery."','".$cart->id."', '".$obj->id."', '1', '0', '0', '1')";
Db::getInstance()->query($sql);
$id_customization = Db::getInstance()->Insert_ID();
$sql = "INSERT INTO `" . _DB_PREFIX_ . "config_product` (`id_cart`, `id_cart_product`, `token`, `page`, `id_customization`, `id_configurator_group`, `date`) VALUES ('".$order->getCartIdStatic($order->id)."','".$obj->id."','".$token."', '0', '".(int)$id_customization."', '0', '".date("Y-m-d H:i:s")."')";
Db::getInstance()->query($sql);
$configProductId = Db::getInstance()->Insert_ID();
$products_links[] = array(
'name' => $product['product_name'],
'url_pdf' => $context->link->getModuleLink('configurator', 'getpdf', array(
'token' => $token
)),
'url_config' => $context->link->getModuleLink('configurator', 'configureproduct', array(
'token' => $token
))
);
}
}
}
if($products_links && count($products_links) > 0) {
$product_var_tpl_list = [];
$product_var_tpl['products_links'] = $products_links;
$product_var_tpl_list[] = $product_var_tpl;
$product_list_html = getEmailTemplateContent('order_conf_product_configs_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list);
$data = [
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{order_name}' => $order->getUniqReference(),
'{product_list_html}' => $product_list_html
];
$orderLanguage = new Language((int) $order->id_lang);
$result = Mail::Send(
(int) $order->id_lang,
'order_configs',
$context->getTranslator()->trans(
'Konfiguracja zakupionych produktów',
[],
'Emails.Subject',
$orderLanguage->locale
),
$data,
$customer->email,
$customer->firstname . ' ' . $customer->lastname,
null,
null,
null,
null,
_PS_MAIL_DIR_,
false,
(int) $order->id_shop
);
$sql = "UPDATE `" . _DB_PREFIX_ . "orders` SET `issendemail` = '1' where `id_order` = '".(int)$order->id."'";
Db::getInstance()->query($sql);
$i++;
}
}
}
echo "Success count(".$i.")";
function getPartialRenderer()
{
$partialRenderer = new MailPartialTemplateRenderer(Context::getContext()->smarty);
return $partialRenderer;
}
function getEmailTemplateContent($template_name, $mail_type, $var)
{
$email_configuration = Configuration::get('PS_MAIL_TYPE');
if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) {
return '';
}
return getPartialRenderer()->render($template_name, Context::getContext()->language, $var);
}
?>