Services
Access services from the plugin instance:
use johnhenry\bundlebuilder\BundleBuilder;
$plugin = BundleBuilder::getInstance();
$plugin->getBundleTypes();
$plugin->getBundlePricing();
$plugin->getBundleCart();services\BundleTypes
CRUD for bundle types, their field layout and per-site settings.
| Method | Description |
|---|---|
getAllBundleTypes(): BundleType[] | All types, indexed by ID (memoized). |
getEditableBundleTypes(): BundleType[] | Types the current user can manage. |
getBundleTypeById(int): ?BundleType | A type by ID. |
getBundleTypeByHandle(string): ?BundleType | A type by handle. |
getBundleTypeSites(int): BundleTypeSite[] | A type's site settings. |
saveBundleType(BundleType, bool): bool | Validate + save a type, its field layout and site settings. |
deleteBundleTypeById(int): bool | Delete a type, its bundles and field layout. |
services\BundlePricing
Automatic pricing.
| Method | Description |
|---|---|
getComponentsSubtotal(Bundle): float | Summed sale price of the components. |
getComponentPrice(Product): float | A component's default-variant sale price (promotional price if one applies, otherwise its regular price). |
calculatePrice(Bundle): float | Components subtotal minus the configured discount |
recalculateBundlesForProduct(int): void |
Re-save automatic bundles containing a product. Queued via jobs\RecalculateBundlePrices rather than called directly; see Pricing. |
services\BundleCart
Cart-time variant resolution, snapshot and inventory.
| Method | Description |
|---|---|
applyToLineItem(Bundle, LineItem): void | Resolve + validate variants, write options + snapshot. |
getSelections(LineItem): array | The component selections from a line item snapshot. |
decrementComponentStock(LineItem): void | Decrement chosen variants' inventory on completion. |
Adjuster
adjusters\BundleTaxAdjuster
Registered on OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS. For multiple supply bundle line items it apportions tax across components by selling-price share, taxing each at its own rate against whatever tax rates/zones/categories are configured in Commerce: VAT, GST, sales tax, or otherwise. See Tax Treatment.