### Discount Configuration Example Source: https://docs.lunarphp.com/1.x/reference/discounts Defines the configuration for a discount, specifying its type, value, minimum price, start and end dates, and usage limits. This example shows how to set up a percentage-based discount with a minimum spend requirement. ```php return [ 'percentage' => 20, 'min_prices' => [ 'USD' => 2000, // $20.00 minimum spend ], 'starts_at' => '2024-01-01 00:00:00', 'ends_at' => null, 'max_uses' => null, ]; ``` -------------------------------- ### Using Custom Models Source: https://docs.lunarphp.com/1.x/extending/models Instantiate and use custom models within your application. This example shows how to get the first product and access its variants. ```php // Somewhere else in your code... $product = \Lunar\Models\Product::first(); $product->variants->first(); // App\Models\ProductVariant ``` -------------------------------- ### Create Buy X Get Y Discount Source: https://docs.lunarphp.com/1.x/reference/discounts Example of creating a 'Buy 2 Get 1 Free' discount. This snippet demonstrates how to define the discount's name, handle, type, and specific data like minimum quantity and reward quantity. ```php $discount = Discount::create([ 'name' => 'Buy 2 Get 1 Free', 'handle' => 'buy_2_get_1', 'type' => 'Lunar\DiscountTypes\BuyXGetY', 'data' => [ 'min_qty' => 2, 'reward_qty' => 1 ] ]); ``` -------------------------------- ### Example: Using Payment Driver with Data Source: https://docs.lunarphp.com/1.x/extending/payments An example demonstrating how to instantiate a payment driver and pass specific data, such as a payment gateway identifier, to it. ```php Payments::driver( 'stripe' )->withData([ // ... ]) ``` -------------------------------- ### Example: Using Payment Driver with Data Source: https://docs.lunarphp.com/1.x/extending/payments An example demonstrating how to select a payment driver and pass specific data to it, such as a payment gateway identifier. ```php Payments::driver('stripe') ->withData([ // ... ]) ``` -------------------------------- ### Install LunarPHP 1.5.0-beta.3 Source: https://docs.lunarphp.com/logs/2026/v1-5-0-beta-3 To install this version, update your composer.json file and consult the upgrade guide for any necessary steps. ```text 1.5.0-beta.3 ``` ```text composer.json ``` -------------------------------- ### BuyXGetY Discount Configuration Example Source: https://docs.lunarphp.com/1.x/reference/discounts Demonstrates the configuration for a BuyXGetY discount. It defines conditions and rewards, which can be products, product variants, or collections. ```php [ 'discountable_conditions' => [ [ 'type' => 'products', 'include_sub_total_discounted_items' => false, 'fixed_quantity' => 2, 'fixed_price' => null, 'fixed_discount' => null, 'fixed_discount_type' => null, 'apply_to' => null, 'discountable_id' => null, 'discountable_type' => null, ] ], 'discountable_rewards' => [ [ 'type' => 'products', 'fixed_quantity' => 1, 'fixed_price' => null, 'fixed_discount' => null, 'fixed_discount_type' => null, 'apply_to' => null, 'discountable_id' => null, 'discountable_type' => null, ] ], ] ``` -------------------------------- ### Install LunarPHP 1.5.0-beta.3 Source: https://docs.lunarphp.com/logs/2026/v1-5-0-beta-3 Update your composer.json file to specify version 1.5.0-beta.3 and consult the upgrade guide before installing on a production project. ```json { "require": { "lunarphp/lunar": "1.5.0-beta.3" } } ``` -------------------------------- ### BuyXGetY Configuration Example Source: https://docs.lunarphp.com/1.x/reference/discounts Configures 'BuyXGetY' discount conditions and rewards. Conditions and rewards can be products, product variants, or collections. ```php Lunar\DiscountTypes\BuyXGetY::configure([ 'starts_at' => now(), 'ends_at' => null, ]); ``` -------------------------------- ### Discount Configuration Example Source: https://docs.lunarphp.com/1.x/reference/discounts Example of how to configure a discount with various parameters like reward quantity, maximum reward quantity, automatic rewards, and time constraints. Use this to define specific discount rules. ```php use Lunar\Models\Discount; $discount = Discount::create([ 'name' => 'Summer Sale', 'type' => 'percentage', 'value' => 10, 'priority' => 1, 'coupon_code' => 'SUMMER10', 'fixed_quantity' => null, 'fixed_value' => null, 'reward_qty' => 1, 'max_reward_qty' => 5, 'automatically_add_rewards' => false, 'starts_at' => now(), 'ends_at' => null, ]); ``` -------------------------------- ### Get a Channel Source: https://docs.lunarphp.com/1.x/reference/channels Retrieves a channel. This is a basic example of accessing channel data. ```javascript Product::channel($channelA).get(); ``` -------------------------------- ### Filtering and Getting Morph Class Source: https://docs.lunarphp.com/1.x/guides/product-listing-page This example shows how to filter a collection by 'element_type' and then retrieve its morph class. It uses 'where' for filtering and 'getMorphClass' to get the class name. ```php $collection = Collection::where( 'element_type', new Collection )->firstOrFail(); ``` -------------------------------- ### Create Product Source: https://docs.lunarphp.com/1.x/reference/products Example of creating a new product with basic details and options. This snippet demonstrates how to instantiate and populate a Product object. ```php use Lunar\\Models\\Product; $product = Product::create([ 'name' => '1460 PATENT LEATHER BOOTS', 'description' => 'Even more shades from the archive...' ]); ``` -------------------------------- ### Cart Item Image Rendering Example Source: https://docs.lunarphp.com/1.x/guides/cart This example shows how to render a product image within a cart item, using a helper function to get the correct thumbnail. ```jsx {{ ``` -------------------------------- ### Creating a Product Source: https://docs.lunarphp.com/1.x/reference/products Shows how to create a new product instance using the Product model and setting its attributes. ```php use Lunar\\Models\\Product; use Lunar\\FieldTypes\\Text; use Lunar\\FieldTypes\\Number; $product = new Product(); $product->name = 'T-Shirt'; $product->slug = 't-shirt'; $product->price = 19.99; $product->description = 'A comfortable cotton t-shirt.'; $product->save(); ``` -------------------------------- ### Percentage Discount Example Source: https://docs.lunarphp.com/1.x/reference/discounts Defines a percentage discount with a minimum spend requirement and a start time. ```php use Lunar\Models\Discount; $discount = Discount::make([ 'name' => 'Summer Sale', 'type' => 'percentage', 'value' => '10%', 'min_prices' => [ 'USD' => 5000, // $50.00 minimum spend ], 'starts_at' => now(), 'ends_at' => null, ]); ``` -------------------------------- ### Get Default Customer Address Source: https://docs.lunarphp.com/1.x/guides/customer-addresses Example of retrieving the default address for a customer. This is useful for shipping or billing. ```php use Lunar\Models\Customer;\n\n$customer = Customer::find(1);\n\n$defaultAddress = $customer->defaultAddress;\n\nif ($defaultAddress) {\n // Use the default address\n} ``` -------------------------------- ### Using Product Models Source: https://docs.lunarphp.com/1.x/reference/products Demonstrates how to use the Product model with type hinting and a where clause. ```php use Lunar\\Models\\Product; use Lunar\\Models\\ProductVariant; use Lunar\\Models\\TaxClass; use Lunar\\Models\\Currency; $product = Product::where(...)->first(); $taxClass = TaxClass::where(...)->first(); $currency = Currency::where(...)->first(); ``` -------------------------------- ### Creating a Product Source: https://docs.lunarphp.com/1.x/reference/products Example of how to create a new product using the Product model and its associated field types. ```php use Lunar\\\\Models\\\\Product; use Lunar\\\\FieldTypes\\\\ ```