Skip to content
Code-Schnipsel Gruppen Projekte
Commit 3c0da142 erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

feat: coupon code now saved in order history; option to let customer choose...

feat: coupon code now saved in order history; option to let customer choose coupon code delivery type
Übergeordneter 4845f05d
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
...@@ -138,6 +138,14 @@ Beste Grüße<br/> ...@@ -138,6 +138,14 @@ Beste Grüße<br/>
<de><![CDATA[[productTitle]__[date]]]></de> <de><![CDATA[[productTitle]__[date]]]></de>
<en><![CDATA[[productTitle]__[date]]]></en> <en><![CDATA[[productTitle]__[date]]]></en>
</locale> </locale>
<locale name="DownloadProduct.Order.history.coupon_code">
<de><![CDATA[Gutschein-Code generiert für Bestellung von Produkt "[productTitle]" (#[productId]) -> [couponCode] ([couponAmount])]]></de>
<en><![CDATA[Coupon code generated for order of product "[productTitle]" (#[productId]) -> [couponCode] ([couponAmount])]]></en>
</locale>
<locale name="DownloadProduct.Order.history.coupon_code_send_mail">
<de><![CDATA[Gutschein-Code "[couponCode]" per E-Mail an Kunden versandt ([customerMail]).]]></de>
<en><![CDATA[Sent coupon code "[couponCode]" to customer via email ([customoerMail]).]]></en>
</locale>
<locale name="CouponCode.tpl.header"> <locale name="CouponCode.tpl.header">
<de><![CDATA[G U T S C H E I N]]></de> <de><![CDATA[G U T S C H E I N]]></de>
<en><![CDATA[C O U P O N]]></en> <en><![CDATA[C O U P O N]]></en>
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<field>673</field> <field>673</field>
<field>674</field> <field>674</field>
<field>675</field> <field>675</field>
<field>679</field>
</fields> </fields>
</fieldCategory> </fieldCategory>
</fieldCategories> </fieldCategories>
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
use QUI\ERP\Discount\EventHandling as DiscountEvents; use QUI\ERP\Discount\EventHandling as DiscountEvents;
use QUI\ERP\Coupons\Products\CouponProductType; use QUI\ERP\Coupons\Products\CouponProductType;
use QUI\ERP\Coupons\Products\CouponProductException; use QUI\ERP\Coupons\Products\CouponProductException;
use QUI\ERP\Accounting\Calc as ErpCalc;
/** /**
* Class Events * Class Events
...@@ -433,7 +434,7 @@ public static function removeCouponsFromSession() ...@@ -433,7 +434,7 @@ public static function removeCouponsFromSession()
protected static function createProductFields() protected static function createProductFields()
{ {
$fields = [ $fields = [
CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => [ CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => [
'title' => [ 'title' => [
'de' => 'Gutschein-Code ist übertragbar', 'de' => 'Gutschein-Code ist übertragbar',
'en' => 'Coupon code is transferable' 'en' => 'Coupon code is transferable'
...@@ -443,7 +444,7 @@ protected static function createProductFields() ...@@ -443,7 +444,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => false 'requiredField' => false
], ],
CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => [ CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => [
'title' => [ 'title' => [
'de' => 'Gutschein-Code per E-Mail senden', 'de' => 'Gutschein-Code per E-Mail senden',
'en' => 'Send coupon code via email' 'en' => 'Send coupon code via email'
...@@ -453,7 +454,7 @@ protected static function createProductFields() ...@@ -453,7 +454,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => false 'requiredField' => false
], ],
CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => [ CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => [
'title' => [ 'title' => [
'de' => 'Gutschein-Code als PDF bereitstellen', 'de' => 'Gutschein-Code als PDF bereitstellen',
'en' => 'Provide coupon code as PDF' 'en' => 'Provide coupon code as PDF'
...@@ -463,7 +464,7 @@ protected static function createProductFields() ...@@ -463,7 +464,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => false 'requiredField' => false
], ],
CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => [ CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => [
'title' => [ 'title' => [
'de' => 'Gutschein Wert', 'de' => 'Gutschein Wert',
'en' => 'Coupon amount' 'en' => 'Coupon amount'
...@@ -473,7 +474,7 @@ protected static function createProductFields() ...@@ -473,7 +474,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => true 'requiredField' => true
], ],
CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => [ CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => [
'title' => [ 'title' => [
'de' => 'Gutschein-Code Gültigkeit (Tage)', 'de' => 'Gutschein-Code Gültigkeit (Tage)',
'en' => 'Coupon code validity (days)' 'en' => 'Coupon code validity (days)'
...@@ -483,7 +484,7 @@ protected static function createProductFields() ...@@ -483,7 +484,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => true 'requiredField' => true
], ],
CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => [ CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => [
'title' => [ 'title' => [
'de' => 'Gutschein-Beschreibung', 'de' => 'Gutschein-Beschreibung',
'en' => 'Coupon description' 'en' => 'Coupon description'
...@@ -493,7 +494,7 @@ protected static function createProductFields() ...@@ -493,7 +494,7 @@ protected static function createProductFields()
'standard' => false, 'standard' => false,
'requiredField' => true 'requiredField' => true
], ],
CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => [ CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => [
'title' => [ 'title' => [
'de' => 'Ist Einzweck-Gutschein (Besteuerung bei Gutschein-Kauf)', 'de' => 'Ist Einzweck-Gutschein (Besteuerung bei Gutschein-Kauf)',
'en' => 'Is single purpose coupon (taxation on voucher purchase)' 'en' => 'Is single purpose coupon (taxation on voucher purchase)'
...@@ -502,6 +503,56 @@ protected static function createProductFields() ...@@ -502,6 +503,56 @@ protected static function createProductFields()
'public' => false, 'public' => false,
'standard' => false, 'standard' => false,
'requiredField' => false 'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => [
'title' => [
'de' => 'Gutschein-Versand',
'en' => 'Coupon delivery'
],
'type' => Fields::TYPE_ATTRIBUTE_LIST,
'public' => true,
'standard' => false,
'requiredField' => true,
'options' => [
'entries' => [
[
'title' => [
'de' => 'per E-Mail',
'en' => 'via email'
],
'sum' => 0,
'type' => ErpCalc::CALCULATION_COMPLEMENT,
'selected' => true,
'userinput' => false
],
[
'title' => [
'de' => 'per Post',
'en' => 'via mail'
],
'sum' => 0,
'type' => ErpCalc::CALCULATION_COMPLEMENT,
'selected' => false,
'userinput' => false
]
]
]
],
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW => [
'title' => [
'de' => 'Kunde darf Gutschein-Versandart wählen',
'en' => 'Customer can choose coupon delivery type'
],
'description' => [
'de' => 'Ist diese Funktion aktiviert, kann der Kunde beim Artikel im Shop wählen, ob der Gutschein'
.' per E-Mail oder Post versandt werden soll.',
'en' => 'If this option is enabled, the customer can choose at the article in the store whether the'
.' coupon should be sent by e-mail or by (physical) mail.'
],
'type' => Fields::TYPE_BOOL,
'public' => false,
'standard' => false,
'requiredField' => false
] ]
]; ];
...@@ -521,6 +572,7 @@ protected static function createProductFields() ...@@ -521,6 +572,7 @@ protected static function createProductFields()
'type' => $field['type'], 'type' => $field['type'],
'titles' => $field['title'], 'titles' => $field['title'],
'workingtitles' => $field['title'], 'workingtitles' => $field['title'],
'description' => !empty($field['description']) ? $field['description'] : null,
'systemField' => 0, 'systemField' => 0,
'standardField' => !empty($field['standard']) ? 1 : 0, 'standardField' => !empty($field['standard']) ? 1 : 0,
'publicField' => !empty($field['public']) ? 1 : 0, 'publicField' => !empty($field['public']) ? 1 : 0,
...@@ -558,13 +610,14 @@ public static function onQuiqqerProductsProductCreate(ProductInterface $Product) ...@@ -558,13 +610,14 @@ public static function onQuiqqerProductsProductCreate(ProductInterface $Product)
$UniqueProduct->calc(); $UniqueProduct->calc();
$fields = [ $fields = [
CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => true, CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => true,
CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => true, CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => true,
CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => true, CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => true,
CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => $UniqueProduct->getPrice()->getValue(), CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => $UniqueProduct->getPrice()->getValue(),
CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => 1095, // 3 years CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => 1095, // 3 years
CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => null, CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => null,
CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => false, CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => false,
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => false
]; ];
foreach ($fields as $fieldId => $value) { foreach ($fields as $fieldId => $value) {
......
...@@ -15,13 +15,51 @@ class CouponProductType extends DigitalProduct ...@@ -15,13 +15,51 @@ class CouponProductType extends DigitalProduct
/** /**
* Special fields for coupon products * Special fields for coupon products
*/ */
const PRODUCT_FIELD_ID_TRANSFERABLE = 670; const PRODUCT_FIELD_ID_TRANSFERABLE = 670;
const PRODUCT_FIELD_ID_GENERATE_PDF = 671; const PRODUCT_FIELD_ID_GENERATE_PDF = 671;
const PRODUCT_FIELD_ID_COUPON_AMOUNT = 672; const PRODUCT_FIELD_ID_COUPON_AMOUNT = 672;
const PRODUCT_FIELD_ID_DAYS_VALID = 673; const PRODUCT_FIELD_ID_DAYS_VALID = 673;
const PRODUCT_FIELD_ID_COUPON_DESCRIPTION = 674; const PRODUCT_FIELD_ID_COUPON_DESCRIPTION = 674;
const PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON = 675; const PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON = 675;
const PRODUCT_FIELD_ID_SEND_MAIL = 676; const PRODUCT_FIELD_ID_SEND_MAIL = 676;
const PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT = 678;
const PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW = 679;
/**
* Model constructor
*
* @param integer $pid - Product-ID
* @param array $product - Product Data
*
* @throws QUI\ERP\Products\Product\Exception
* @throws QUI\Exception
*/
public function __construct($pid, $product = [])
{
parent::__construct($pid, $product);
if (!empty($this->fields[self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW])) {
$userDeliveryTypeSelectAllow = $this->getFieldValue(
self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW
);
if ($userDeliveryTypeSelectAllow) {
try {
$Field = QUI\ERP\Products\Handler\Fields::getField(
self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT
);
$Field->setProduct($this);
$this->fields[$Field->getId()] = $Field;
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
} else {
unset($this->fields[self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT]);
}
}
}
/** /**
* @param QUI\Locale $Locale * @param QUI\Locale $Locale
......
...@@ -30,6 +30,7 @@ class Handler ...@@ -30,6 +30,7 @@ class Handler
public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $Order): void public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $Order): void
{ {
$Customer = $Order->getCustomer(); $Customer = $Order->getCustomer();
$Currency = $Order->getCurrency();
/** @var QUI\ERP\Accounting\Article $Article */ /** @var QUI\ERP\Accounting\Article $Article */
foreach ($Order->getArticles() as $Article) { foreach ($Order->getArticles() as $Article) {
...@@ -49,6 +50,21 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O ...@@ -49,6 +50,21 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
$CouponCode = self::createCouponCodeFromProduct($Product, $Order, $Customer); $CouponCode = self::createCouponCodeFromProduct($Product, $Order, $Customer);
$couponFilePathCustomerDir = null; $couponFilePathCustomerDir = null;
$Order->addHistory(
QUI::getLocale()->get(
'quiqqer/coupons',
'DownloadProduct.Order.history.coupon_code',
[
'couponCode' => $CouponCode->getCode(),
'productTitle' => $Product->getTitle(),
'productId' => $Product->getId(),
'couponAmount' => $Currency->format(
$Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT)
)
]
)
);
// Generate coupon PDF // Generate coupon PDF
if ($Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF)) { if ($Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF)) {
$couponPdfFile = self::createCouponCodePdf($CouponCode, $Product); $couponPdfFile = self::createCouponCodePdf($CouponCode, $Product);
...@@ -80,8 +96,43 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O ...@@ -80,8 +96,43 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
} }
// Send coupon via email // Send coupon via email
if ($Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL)) {
/*
* Check if customer explicitly chose "send by email"
*/
$deliveryTypeFieldData = $Article->getCustomField(
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT
);
if ($deliveryTypeFieldData) {
switch ($deliveryTypeFieldData['value']) {
// by mail
case 1:
$sendMail = false;
break;
// by email
default:
$sendMail = true;
}
} else {
$sendMail = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL);
}
if ($sendMail) {
self::sendCouponMail($CouponCode, $Product, $Customer, $couponFilePathCustomerDir); self::sendCouponMail($CouponCode, $Product, $Customer, $couponFilePathCustomerDir);
$Order->addHistory(
QUI::getLocale()->get(
'quiqqer/coupons',
'DownloadProduct.Order.history.coupon_code_send_mail',
[
'couponCode' => $CouponCode->getCode(),
'customerMail' => QUI\ERP\Customer\Utils::getInstance()->getEmailByCustomer($Customer)
]
)
);
} }
} catch (\Exception $Exception) { } catch (\Exception $Exception) {
if ($Exception->getCode() === 404) { if ($Exception->getCode() === 404) {
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren