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

refactor: separation of physical and digital products

Übergeordneter bfa09761
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -193,9 +193,21 @@ Best Wishes<br/>
<de><![CDATA[Bitte fülle alle Pflichtfelder aus.]]></de>
<en><![CDATA[Please fill out all required fields.]]></en>
</locale>
<locale name="product_type.CouponProductType.title">
<de><![CDATA[Gutschein]]></de>
<en><![CDATA[Coupon]]></en>
<locale name="product_type.DigitalCouponProductType.title">
<de><![CDATA[Gutschein (digital)]]></de>
<en><![CDATA[Coupon (digital)]]></en>
</locale>
<locale name="product_type.DigitalCouponProductType.description">
<de><![CDATA[Gutschein, der ausschließlich digital angeboten wird (Versand per E-Mail und/oder PDF-Download).]]></de>
<en><![CDATA[Coupon offered exclusively digitally (sent by e-mail and/or PDF download).]]></en>
</locale>
<locale name="product_type.PhysicalCouponProductType.title">
<de><![CDATA[Gutschein (physisch)]]></de>
<en><![CDATA[Coupon (physical)]]></en>
</locale>
<locale name="product_type.PhysicalCouponProductType.description">
<de><![CDATA[Gutschein, der physisch erstellt und versandt wird (kann zusätzlich auch digital angeboten werden).]]></de>
<en><![CDATA[Coupon that is physically created and shipped (can additionally be offered digitally).]]></en>
</locale>
<!-- Ajax -->
......
......@@ -24,7 +24,8 @@
</copyright>
<provider>
<productType src="\QUI\ERP\Coupons\Products\CouponProductType"/>
<productType src="\QUI\ERP\Coupons\Products\DigitalCouponProductType"/>
<productType src="\QUI\ERP\Coupons\Products\PhysicalCouponProductType"/>
</provider>
</package>
......
......@@ -11,9 +11,11 @@
use QUI\ERP\Order\Basket\BasketGuest;
use QUI\ERP\Coupons\Handler as CouponsHandler;
use QUI\ERP\Discount\EventHandling as DiscountEvents;
use QUI\ERP\Coupons\Products\CouponProductType;
use QUI\ERP\Coupons\Products\DigitalCouponProductType;
use QUI\ERP\Coupons\Products\PhysicalCouponProductType;
use QUI\ERP\Coupons\Products\CouponProductException;
use QUI\ERP\Accounting\Calc as ErpCalc;
use QUI\ERP\Coupons\Products\Handler as CouponProductsHandler;
/**
* Class Events
......@@ -434,7 +436,7 @@ public static function removeCouponsFromSession()
protected static function createProductFields()
{
$fields = [
CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => [
CouponProductsHandler::PRODUCT_FIELD_ID_TRANSFERABLE => [
'title' => [
'de' => 'Gutschein-Code ist übertragbar',
'en' => 'Coupon code is transferable'
......@@ -451,7 +453,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => [
CouponProductsHandler::PRODUCT_FIELD_ID_SEND_MAIL => [
'title' => [
'de' => 'Gutschein-Code per E-Mail senden',
'en' => 'Send coupon code via email'
......@@ -469,7 +471,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => [
CouponProductsHandler::PRODUCT_FIELD_ID_GENERATE_PDF => [
'title' => [
'de' => 'Gutschein-Code als PDF bereitstellen',
'en' => 'Provide coupon code as PDF'
......@@ -487,7 +489,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => [
CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_AMOUNT => [
'title' => [
'de' => 'Gutschein Wert',
'en' => 'Coupon amount'
......@@ -497,7 +499,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => true
],
CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => [
CouponProductsHandler::PRODUCT_FIELD_ID_DAYS_VALID => [
'title' => [
'de' => 'Gutschein-Code Gültigkeit (Tage)',
'en' => 'Coupon code validity (days)'
......@@ -507,7 +509,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => true
],
CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => [
CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => [
'title' => [
'de' => 'Gutschein-Beschreibung',
'en' => 'Coupon description'
......@@ -519,9 +521,9 @@ protected static function createProductFields()
'type' => Fields::TYPE_INPUT_MULTI_LANG,
'public' => false,
'standard' => false,
'requiredField' => true
'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => [
CouponProductsHandler::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => [
'title' => [
'de' => 'Ist Einzweck-Gutschein (Besteuerung bei Gutschein-Kauf)',
'en' => 'Is single purpose coupon (taxation on voucher purchase)'
......@@ -541,7 +543,7 @@ protected static function createProductFields()
'standard' => false,
'requiredField' => false
],
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => [
CouponProductsHandler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => [
'title' => [
'de' => 'Gutschein - Versand',
'en' => 'Coupon delivery'
......@@ -575,7 +577,7 @@ protected static function createProductFields()
]
]
],
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW => [
CouponProductsHandler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW => [
'title' => [
'de' => 'Kunde darf Gutschein - Versandart wählen',
'en' => 'Customer can choose coupon delivery type'
......@@ -639,22 +641,23 @@ protected static function createProductFields()
*/
public static function onQuiqqerProductsProductCreate(ProductInterface $Product)
{
if (!($Product instanceof CouponProductType)) {
if (!($Product instanceof DigitalCouponProductType) && !($Product instanceof PhysicalCouponProductType)) {
return;
}
$isDigital = $Product instanceof DigitalCouponProductType;
$UniqueProduct = $Product->createUniqueProduct();
$UniqueProduct->calc();
$fields = [
CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE => true,
CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL => true,
CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF => true,
CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT => $UniqueProduct->getPrice()->getValue(),
CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID => 1095, // 3 years
CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => null,
CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => false,
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => false
CouponProductsHandler::PRODUCT_FIELD_ID_TRANSFERABLE => true,
CouponProductsHandler::PRODUCT_FIELD_ID_SEND_MAIL => $isDigital,
CouponProductsHandler::PRODUCT_FIELD_ID_GENERATE_PDF => $isDigital,
CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_AMOUNT => $UniqueProduct->getPrice()->getValue(),
CouponProductsHandler::PRODUCT_FIELD_ID_DAYS_VALID => 1095, // 3 years
CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_DESCRIPTION => null,
CouponProductsHandler::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => false,
CouponProductsHandler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT => false
];
foreach ($fields as $fieldId => $value) {
......@@ -694,11 +697,11 @@ public static function onQuiqqerProductsProductCreate(ProductInterface $Product)
*/
public static function onQuiqqerProductsProductActivate(ProductInterface $Product)
{
if (!($Product instanceof CouponProductType)) {
if (!($Product instanceof DigitalCouponProductType) && !($Product instanceof PhysicalCouponProductType)) {
return;
}
$isSinglePurposeCoupon = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON);
$isSinglePurposeCoupon = $Product->getFieldValue(CouponProductsHandler::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON);
if (!empty($isSinglePurposeCoupon)) {
return;
......
......@@ -8,23 +8,10 @@
/**
* Class DigitalProduct
*
* Represents a non-physical product that does not require shipping.
* Represents a non-physical coupon that does not require shipping.
*/
class CouponProductType extends DigitalProduct
class DigitalCouponProductType extends DigitalProduct
{
/**
* Special fields for coupon products
*/
const PRODUCT_FIELD_ID_TRANSFERABLE = 670;
const PRODUCT_FIELD_ID_GENERATE_PDF = 671;
const PRODUCT_FIELD_ID_COUPON_AMOUNT = 672;
const PRODUCT_FIELD_ID_DAYS_VALID = 673;
const PRODUCT_FIELD_ID_COUPON_DESCRIPTION = 674;
const PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON = 675;
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
*
......@@ -38,15 +25,15 @@ public function __construct($pid, $product = [])
{
parent::__construct($pid, $product);
if (!empty($this->fields[self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW])) {
if (!empty($this->fields[Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW])) {
$userDeliveryTypeSelectAllow = $this->getFieldValue(
self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW
Handler::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
Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT
);
$Field->setProduct($this);
......@@ -56,7 +43,7 @@ public function __construct($pid, $product = [])
QUI\System\Log::writeException($Exception);
}
} else {
unset($this->fields[self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT]);
unset($this->fields[Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT]);
}
}
}
......@@ -71,7 +58,7 @@ public static function getTypeTitle($Locale = null)
$Locale = QUI::getLocale();
}
return $Locale->get('quiqqer/coupons', 'product_type.CouponProductType.title');
return $Locale->get('quiqqer/coupons', 'product_type.DigitalCouponProductType.title');
}
/**
......@@ -84,6 +71,6 @@ public static function getTypeDescription($Locale = null)
$Locale = QUI::getLocale();
}
return $Locale->get('quiqqer/coupons', 'product_type.CouponProductType.description');
return $Locale->get('quiqqer/coupons', 'product_type.DigitalCouponProductType.description');
}
}
......@@ -19,6 +19,19 @@
*/
class Handler
{
/**
* Special fields for coupon products
*/
const PRODUCT_FIELD_ID_TRANSFERABLE = 670;
const PRODUCT_FIELD_ID_GENERATE_PDF = 671;
const PRODUCT_FIELD_ID_COUPON_AMOUNT = 672;
const PRODUCT_FIELD_ID_DAYS_VALID = 673;
const PRODUCT_FIELD_ID_COUPON_DESCRIPTION = 674;
const PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON = 675;
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;
/**
* Create coupons from all coupon products of an order.
*
......@@ -43,7 +56,8 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
$Product = ProductsHandler::getProduct($Article->getId());
// Only parse coupon products
if (!($Product instanceof CouponProductType)) {
if (!($Product instanceof DigitalCouponProductType) &&
!($Product instanceof PhysicalCouponProductType)) {
continue;
}
......@@ -59,14 +73,14 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
'productTitle' => $Product->getTitle(),
'productId' => $Product->getId(),
'couponAmount' => $Currency->format(
$Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT)
$Product->getFieldValue(self::PRODUCT_FIELD_ID_COUPON_AMOUNT)
)
]
)
);
// Generate coupon PDF
if ($Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_GENERATE_PDF)) {
if ($Product->getFieldValue(self::PRODUCT_FIELD_ID_GENERATE_PDF)) {
$couponPdfFile = self::createCouponCodePdf($CouponCode, $Product);
// Rename file
......@@ -101,7 +115,7 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
* Check if customer explicitly chose "send by email"
*/
$deliveryTypeFieldData = $Article->getCustomField(
CouponProductType::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT
self::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT
);
if ($deliveryTypeFieldData) {
......@@ -116,7 +130,7 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
$sendMail = true;
}
} else {
$sendMail = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_SEND_MAIL);
$sendMail = $Product->getFieldValue(self::PRODUCT_FIELD_ID_SEND_MAIL);
}
if ($sendMail) {
......@@ -173,7 +187,7 @@ protected static function createCouponCodeFromProduct(
];
// Valid until
$daysValid = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_DAYS_VALID);
$daysValid = $Product->getFieldValue(self::PRODUCT_FIELD_ID_DAYS_VALID);
if (empty($daysValid)) {
$daysValid = 1095; // 3 years;
......@@ -183,7 +197,7 @@ protected static function createCouponCodeFromProduct(
$couponAttributes['validUntilDate'] = $ValidUntil->format('Y-m-d');
// Transferable (=usable by other users or guests)
$isTransferable = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_TRANSFERABLE);
$isTransferable = $Product->getFieldValue(self::PRODUCT_FIELD_ID_TRANSFERABLE);
if (empty($isTransferable)) {
$couponAttributes['userIds'] = [$User->getId()];
......@@ -204,7 +218,7 @@ protected static function createDiscountFromProduct(Product $Product): Discount
{
$Handler = DiscountHandler::getInstance();
$discountAmount = $Product->getFieldValue(CouponProductType::PRODUCT_FIELD_ID_COUPON_AMOUNT);
$discountAmount = $Product->getFieldValue(self::PRODUCT_FIELD_ID_COUPON_AMOUNT);
if (empty($discountAmount)) {
$discountAmount = $Product->getPrice()->getValue();
......@@ -212,7 +226,7 @@ protected static function createDiscountFromProduct(Product $Product): Discount
// Determine discount calculation basis based on coupon type
$isProductSpecificCoupon = $Product->getFieldValue(
CouponProductType::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON
self::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON
);
// @todo für Einzweck-Gutscheine muss ein spezieller Rabatt-Typ verwendet werden
......@@ -411,7 +425,7 @@ protected static function getCouponViewData(CouponCode $CouponCode, Product $Pro
'productTitle' => $Product->getTitle(),
'userName' => $User ? $User->getName() : false,
'couponDescription' => $Product->getFieldValueByLocale(
CouponProductType::PRODUCT_FIELD_ID_COUPON_DESCRIPTION
self::PRODUCT_FIELD_ID_COUPON_DESCRIPTION
),
'discountAmountFormatted' => $DiscountAmount->getDisplayPrice(),
'createDateFormatted' => $Locale->formatDate(
......
<?php
namespace QUI\ERP\Coupons\Products;
use QUI;
use QUI\ERP\Products\Product\Types\DigitalProduct;
/**
* Class PhysicalCouponProductType
*
* Represents a physical coupon that requires shipping.
*/
class PhysicalCouponProductType extends QUI\ERP\Products\Product\Types\AbstractType
{
/**
* 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[Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW])) {
$userDeliveryTypeSelectAllow = $this->getFieldValue(
Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT_ALLOW
);
if ($userDeliveryTypeSelectAllow) {
try {
$Field = QUI\ERP\Products\Handler\Fields::getField(
Handler::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[Handler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT]);
}
}
}
/**
* @param QUI\Locale $Locale
* @return string
*/
public static function getTypeTitle($Locale = null)
{
if ($Locale === null) {
$Locale = QUI::getLocale();
}
return $Locale->get('quiqqer/coupons', 'product_type.PhysicalCouponProductType.title');
}
/**
* @param QUI\Locale $Locale
* @return string
*/
public static function getTypeDescription($Locale = null)
{
if ($Locale === null) {
$Locale = QUI::getLocale();
}
return $Locale->get('quiqqer/coupons', 'product_type.PhysicalCouponProductType.description');
}
}
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