Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Sep 13, 2024
2 parents bde4d94 + 7d29860 commit 7ae014d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/PaymentMethodSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected function setData()

$method = PaymentMethod::where('id', $this->order->payment_method_id ?? $this->cart->payment_method_id)->first();

$this->setVar('methods', PaymentMethod::orderBy('sort_order', 'ASC')->get());
$this->setVar('paymentMethods', PaymentMethod::getAvailableByCart($this->cart));
$this->setVar('customerMethods', $this->getCustomerMethods());
$this->setVar('activeMethod', $method);
$this->setVar('shippingSelectionBeforePayment', GeneralSettings::get('shipping_selection_before_payment', false)); // Needed by themes
Expand Down
4 changes: 3 additions & 1 deletion components/QuickCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ protected function setData()
$paymentMethod = PaymentMethod::getDefault();
$cart->setPaymentMethod($paymentMethod);
}
$this->setVar('paymentMethods', PaymentMethod::orderBy('sort_order', 'ASC')->get());

$this->setVar('paymentMethods', PaymentMethod::getAvailableByCart($cart));

$this->setVar('customerPaymentMethods', $this->getCustomerMethods());

// $this->setVar('dataLayer', $this->handleDataLayer());
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig({
},
siteTitle: false,
editLink: {
pattern: 'https://github.com/OFFLINE-GmbH/oc-mall-plugin/edit/develop/src/docs/:path',
pattern: 'https://github.com/OFFLINE-GmbH/oc-mall-plugin/tree/next/docs/:path',
text: 'Edit this page on GitHub'
},
lastUpdated: {
Expand Down
4 changes: 4 additions & 0 deletions docs/development/core/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ This event is emitted when the quantity of a cart product has changed. It receiv
* `oldQuantity` the old quantity value
* `newQuantity` the new quantity value

### `mall.cart.extendAvailablePaymentMethods`

This event allows to customize the payment methods based on the current cart.

## Checkout

### `mall.checkout.succeeded`
Expand Down
7 changes: 0 additions & 7 deletions docs/development/extend/unit-testing.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<script setup>
import BadgeStd from '../../.vitepress/components/BadgeStd.vue'
import SpoilerStd from '../../.vitepress/components/SpoilerStd.vue'
</script>

# Unit Testing

<BadgeStd label="Page is Work in Progress" color="danger" />

## 1. Install packages

The following dependencies must be installed directly in the root folder of your OctoberCMS
Expand Down
3 changes: 3 additions & 0 deletions docs/development/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Development

This section of the docs tells you how to extend the Mall plugin.
16 changes: 16 additions & 0 deletions models/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use October\Rain\Database\Traits\Sortable;
use October\Rain\Database\Traits\Validation;
use October\Rain\Parse\Twig;
use October\Rain\Support\Facades\Event;
use OFFLINE\Mall\Classes\Database\IsStates;
use OFFLINE\Mall\Classes\Payments\PaymentGateway;
use OFFLINE\Mall\Classes\Totals\PaymentTotal;
Expand Down Expand Up @@ -206,6 +207,21 @@ public static function getDefault(): ?self
return $default;
}

/**
* Get all available payment methods.
* @param Cart $cart
* @return mixed
*/
public static function getAvailableByCart(Cart $cart)
{
$results = array_filter(Event::fire('mall.cart.extendAvailablePaymentMethods', [$cart]) ?? []);
if (count($results) > 0) {
return $results[0];
}

return PaymentMethod::orderBy('sort_order', 'ASC')->get();
}

/**
* Include all payment methods, even disabled ones.
* @param Builder $query
Expand Down
2 changes: 2 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,5 @@ v3.5.0:
- 'Free orders no longer require a payment'
v3.5.1:
- 'Fixed RainLab.User 3.0 Auth facade compatibility'
v3.5.2:
- 'Added mall.cart.extendAvailablePaymentMethods to filter payment methods based on the current cart'

0 comments on commit 7ae014d

Please sign in to comment.