setDiscount example

if ($customerGroup) {
                    $discountModel = $discountRepository->findOneBy([
                        'group' => $customerGroup,
                        'discount' => $discount['discount'],
                        'value' => $discount['value'],
                    ]);
                }

                if ($discountModel === null) {
                    $discountModel = new Discount();
                }
                $discountModel->setDiscount($discount['discount']);
                $discountModel->setValue($discount['value']);
                $discounts[] = $discountModel;
            }
            $params['discounts'] = $discounts;
        } else {
            $params['discounts'] = [];
        }

        return $params;
    }
}
case 'customerGroup':
                if (isset($data['discounts'])) {
                    if (!$model instanceof CustomerGroup) {
                        throw new RuntimeException(sprintf('Model object is not an instance of expected class "%s"', CustomerGroup::class));
                    }
                    $model->getDiscounts()->clear();
                    $manager->flush();
                    $discounts = [];
                    foreach ($data['discounts'] as $discountData) {
                        $discount = new Discount();
                        $discount->setDiscount($discountData['discount']);
                        $discount->setValue($discountData['value']);
                        $discount->setGroup($model);
                        $discounts[] = $discount;
                    }

                    $data['discounts'] = $discounts;
                }
                if (empty($data['mode'])) {
                    $data['discount'] = 0;
                }
                break;

            
$price->setId((int) $row['id']);

            if (isset($row['price'])) {
                $price->setPrice((float) $row['price']);
            }

            if (isset($row['subscription'])) {
                $price->setSubscription((bool) $row['subscription']);
            }

            if (isset($row['discount'])) {
                $price->setDiscount($row['discount']);
            }

            if (isset($row['duration'])) {
                $price->setDuration($row['duration']);
            }

            $prices[] = $price;
        }

        return $prices;
    }

    
Home | Imprint | This part of the site doesn't use cookies.