Skip to content

Commit

Permalink
Fixed #107 syncing products with emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Apr 15, 2024
1 parent 72482b3 commit 8829fca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a PHP error that could occur when syncing products with emojis. ([#107](https://github.com/craftcms/shopify/issues/107))
- Fixed a PHP error that could occur when syncing products. ([#105](https://github.com/craftcms/shopify/issues/105))

## 4.1.1 - 2024-04-09
Expand Down
10 changes: 10 additions & 0 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class Product extends Element
*/
public ?string $vendor = null;

/**
* @inheritdoc
*/
public function init(): void
{
$this->title = $this->title ? StringHelper::shortcodesToEmoji($this->title) : null;
$this->bodyHtml = $this->bodyHtml ? StringHelper::shortcodesToEmoji($this->bodyHtml) : null;
parent::init();
}

/**
* @inheritdoc
*/
Expand Down
5 changes: 3 additions & 2 deletions src/services/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use craft\helpers\ArrayHelper;
use craft\helpers\Db;
use craft\helpers\ProjectConfig;
use craft\helpers\StringHelper;
use craft\models\FieldLayout;
use craft\shopify\elements\Product;
use craft\shopify\elements\Product as ProductElement;
Expand Down Expand Up @@ -144,8 +145,8 @@ public function createOrUpdateProduct(ShopifyProduct $product, array $metafields
// Build our attribute set from the Shopify product data:
$attributes = [
'shopifyId' => $product->id,
'title' => $product->title,
'bodyHtml' => $product->body_html,
'title' => $product->title ? StringHelper::emojiToShortcodes($product->title) : null,
'bodyHtml' => $product->body_html ? StringHelper::emojiToShortcodes($product->body_html) : null,
'createdAt' => Db::prepareDateForDb($product->created_at),
'handle' => $product->handle,
'images' => $product->images,
Expand Down

0 comments on commit 8829fca

Please sign in to comment.