Skip to content

Commit

Permalink
Merge branch '1.3' into feature/42-stripe-data-reset-command
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Nov 19, 2024
2 parents 86b488e + 16a44d4 commit aa610b0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Fixed getting a default price for a Product element. ([#40](https://github.com/craftcms/stripe/pull/40))
- Fixed an issue that could occur when installing or running migration on MariaDB. ([#51](https://github.com/craftcms/stripe/issues/51))
- Fixed a styling issue with Stripe’s element’s meta card footer.
- Added `stripe/data/reset` CLI command. ([#42](https://github.com/craftcms/stripe/issues/42))

## 1.2.0.2 - 2024-11-08
Expand Down
38 changes: 19 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,21 @@ public function getData(): array
public function getDefaultPrice(): Price|null
{
if (!isset($this->_defaultPrice)) {
if ($this->getData()['default_price'] === null) {
$defaultPriceId = $this->getData()['default_price'];
if ($defaultPriceId === null) {
return null;
}

// depending on whether we're expanding a default_price when getting a product from Stripe, this will be a string or an array
if (is_array($defaultPriceId)) {
$defaultPriceId = $defaultPriceId['id'];
}

/** @var ElementCollection<int|string, Price> $prices */
$prices = $this->getPrices();

$price = $prices
->filter(fn(Price $price) => $price->stripeId === $this->getData()['default_price'])
->filter(fn(Price $price) => $price->stripeId === $defaultPriceId)
->first();

if (!$price) {
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private function createGeneratedColumns(): void
// latestInvoiceId
$this->execute("ALTER TABLE " . Table::SUBSCRIPTIONDATA . " ADD COLUMN " .
$db->quoteColumnName('latestInvoiceId') . " VARCHAR(255) GENERATED ALWAYS AS (" .
$qb->jsonExtract('data', ['latest_invoice']) . ") STORED NULL;");
$qb->jsonExtract('data', ['latest_invoice']) . ") STORED;");
// startDate
$this->execute("ALTER TABLE " . Table::SUBSCRIPTIONDATA . " ADD COLUMN " .
$db->quoteColumnName('startDate') . " VARCHAR(255) GENERATED ALWAYS AS (" .
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/m240819_121818_loosen_aux_data_uniq.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function safeUp(): bool
// Step 3: Recreate the virtual column as nullable: https://docs.stripe.com/api/subscriptions/object#subscription_object-latest_invoice
$this->execute("ALTER TABLE " . $tableName . " ADD COLUMN " .
$this->db->quoteColumnName('[[latestInvoiceId]]') . " VARCHAR(255) GENERATED ALWAYS AS (" .
$this->db->getQueryBuilder()->jsonExtract('data', ['latest_invoice']) . ") STORED NULL");
$this->db->getQueryBuilder()->jsonExtract('data', ['latest_invoice']) . ") STORED");

// Step 4: Create a new non-unique index
$this->createIndex(null, $tableName, ['latestInvoiceId'], unique: false);
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/stripecp/dist/css/stripecp.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aa610b0

Please sign in to comment.