90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
|
|
use KupShop\KupShopBundle\Context\CurrencyContext;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use KupShop\OrderingBundle\Util\Discount\DiscountGenerator;
|
|
|
|
$main_class = 'DiscountsDesign';
|
|
|
|
class DiscountsDesign extends Window
|
|
{
|
|
protected $tableName = 'discounts';
|
|
protected $template = 'window/OrderDiscountsCouponsDesign.tpl';
|
|
|
|
public function get_vars()
|
|
{
|
|
$vars = parent::get_vars();
|
|
|
|
$pageVars = getVal('body', $vars);
|
|
$pageVars['data'] = $this->getData();
|
|
|
|
$vars['body'] = $pageVars;
|
|
$vars['type'] = 'discounts';
|
|
|
|
return $vars;
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
$data = parent::getData();
|
|
|
|
if ($ID = $this->getID()) {
|
|
$discount = $this->getObject();
|
|
$this->unserializeCustomData($discount);
|
|
$data = array_merge($data, $discount);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function handleUpdate()
|
|
{
|
|
if ($this->getID()) {
|
|
$data = $this->getData();
|
|
$json = getVal('JSON', $data);
|
|
$svg = getVal('SVG', $data);
|
|
$data = getVal('data', $data);
|
|
$data['JSON'] = json_decode($json, true);
|
|
$data['SVG'] = $svg;
|
|
$this->updateSQL('discounts', ['data' => json_encode($data)], ['id' => $this->getID()]);
|
|
|
|
writeDownActivity(sprintf(translate('activitySVGSaved', 'OrderDiscountsCoupons'), $this->getData()['descr']));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function handlePreviewPDF()
|
|
{
|
|
if ($this->getID()) {
|
|
$data = $this->getData();
|
|
$discount_data = getVal('data', $data);
|
|
$svg = getVal('previewSVG');
|
|
$discount_data['SVG'] = $svg;
|
|
|
|
$discountGenerator = ServiceContainer::getService(DiscountGenerator::class);
|
|
|
|
$code = $data['condition_value'].$discountGenerator->generateRandomCode();
|
|
$date_to = date('d.m.Y', time() + 86400 *
|
|
(!empty($discount_data['valid_months']) ? 30.5 * $discount_data['valid_months'] :
|
|
(!empty($discount_data['valid_days']) ? $discount_data['valid_days'] : 30.5)
|
|
)
|
|
);
|
|
$currency = Contexts::get(CurrencyContext::class)->getDefaultId();
|
|
$coupon = ['id' => null, 'code' => $code, 'date_to' => $date_to, 'price' => '1234', 'currency' => $currency];
|
|
|
|
$pdf = $discountGenerator->generatePDFCoupon($coupon, $discount_data);
|
|
if ($pdf) {
|
|
header('Content-type: application/pdf');
|
|
header('Content-Disposition: inline; filename="CouponExample.pdf"');
|
|
echo $pdf;
|
|
} else {
|
|
$this->returnError(translate('PDFcouponError', 'OrderDiscountsCoupons'));
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|