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

refactor: different default fields for physical / digital products

Übergeordneter 14b2070b
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -650,16 +650,20 @@ public static function onQuiqqerProductsProductCreate(ProductInterface $Product)
$UniqueProduct->calc();
$fields = [
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
// CouponProductsHandler::PRODUCT_FIELD_ID_TRANSFERABLE => true,
CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_AMOUNT => $UniqueProduct->getPrice()->getValue(),
CouponProductsHandler::PRODUCT_FIELD_ID_DAYS_VALID => 1095, // 3 years
CouponProductsHandler::PRODUCT_FIELD_ID_IS_SINGLE_PURPOSE_COUPON => false
];
// Digital coupons get some extra fields
if ($isDigital) {
$fields[CouponProductsHandler::PRODUCT_FIELD_ID_SEND_MAIL] = true;
$fields[CouponProductsHandler::PRODUCT_FIELD_ID_GENERATE_PDF] = true;
$fields[CouponProductsHandler::PRODUCT_FIELD_ID_USER_DELIVERY_TYPE_SELECT] = false;
$fields[CouponProductsHandler::PRODUCT_FIELD_ID_COUPON_DESCRIPTION] = null;
}
foreach ($fields as $fieldId => $value) {
try {
$Field = Fields::getField($fieldId);
......
......@@ -79,6 +79,13 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
)
);
/**
* Physical coupons are not sent via mail or PDF
*/
if ($Product instanceof PhysicalCouponProductType) {
continue;
}
// Generate coupon PDF
if ($Product->getFieldValue(self::PRODUCT_FIELD_ID_GENERATE_PDF)) {
$couponPdfFile = self::createCouponCodePdf($CouponCode, $Product);
......@@ -197,10 +204,12 @@ protected static function createCouponCodeFromProduct(
$couponAttributes['validUntilDate'] = $ValidUntil->format('Y-m-d');
// Transferable (=usable by other users or guests)
$isTransferable = $Product->getFieldValue(self::PRODUCT_FIELD_ID_TRANSFERABLE);
if ($Product->hasField(self::PRODUCT_FIELD_ID_TRANSFERABLE)) {
$isTransferable = $Product->getFieldValue(self::PRODUCT_FIELD_ID_TRANSFERABLE);
if (empty($isTransferable)) {
$couponAttributes['userIds'] = [$User->getId()];
if (empty($isTransferable)) {
$couponAttributes['userIds'] = [$User->getId()];
}
}
return CouponsHandler::createCouponCode([$Discount->getId()], $couponAttributes);
......
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