Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.3 #125

Open
wants to merge 9 commits into
base: 5.x
Choose a base branch
from
Open

5.3 #125

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- '5.x'
- '5.3'
pull_request:
permissions:
contents: read
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Release Notes for Shopify 5.3 (WIP)

- Shopify now requires Craft CMS 5.3.0 or later.
- Added support for selecting products in Link fields.
- Syncing products now returns presentment prices by default. ([#122](https://github.com/craftcms/shopify/issues/122))
- Added `craft\shopify\linktypes\Product`.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"prefer-stable": true,
"require": {
"php": "^8.2",
"craftcms/cms": "^5.0.0-beta.10",
"craftcms/cms": "^5.3.0",
"shopify/shopify-api": "^5.2.0"
},
"require-dev": {
Expand Down
1,470 changes: 917 additions & 553 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
use craft\events\DefineConsoleActionsEvent;
use craft\events\RegisterComponentTypesEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\fields\Link;
use craft\helpers\UrlHelper;
use craft\services\Elements;
use craft\services\Fields;
use craft\services\Utilities;
use craft\shopify\elements\Product;
use craft\shopify\fields\Products as ProductsField;
use craft\shopify\handlers\Product as ProductHandler;
use craft\shopify\linktypes\Product as ProductLinkType;
use craft\shopify\models\Settings;
use craft\shopify\services\Api;
use craft\shopify\services\Products;
Expand Down Expand Up @@ -113,6 +115,7 @@ public function init()
$this->_registerElementTypes();
$this->_registerUtilityTypes();
$this->_registerFieldTypes();
$this->_registerLinkTypes();
$this->_registerVariables();
$this->_registerResaveCommands();

Expand Down Expand Up @@ -214,6 +217,22 @@ private function _registerFieldTypes(): void
});
}

/**
* Register Link types
*
* @since 5.2.0
*/
private function _registerLinkTypes(): void
{
if (!class_exists(Link::class)) {
return;
}

Event::on(Link::class, Link::EVENT_REGISTER_LINK_TYPES, function(RegisterComponentTypesEvent $event) {
$event->types[] = ProductLinkType::class;
});
}

/**
* Register Shopify twig variables to the main craft variable
*
Expand Down
36 changes: 36 additions & 0 deletions src/linktypes/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\shopify\linktypes;

use craft\fields\linktypes\BaseElementLinkType;
use craft\shopify\elements\Product as ProductElement;

/**
* Shopify Product link type.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.3.0
*/
class Product extends BaseElementLinkType
{
/**
* @inheritdoc
*/
protected static function elementType(): string
{
return ProductElement::class;
}

/**
* @inheritdoc
*/
public static function displayName(): string
{
return ProductElement::lowerDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace craft\shopify\migrations;

use Craft;
use craft\db\Migration;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/services/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
use craft\helpers\App;
use craft\log\MonologTarget;
use craft\shopify\Plugin;
use GuzzleHttp\Client;
use Psr\Http\Client\ClientInterface;
use Shopify\Auth\FileSessionStorage;
use Shopify\Auth\Session;
use Shopify\Clients\HttpClientFactory;
use Shopify\Clients\Rest;
use Shopify\Context;
use Shopify\Rest\Admin2023_10\Metafield as ShopifyMetafield;
Expand Down Expand Up @@ -255,6 +258,14 @@ public function getSession(): ?Session
logger: $webLogTarget->getLogger(),
);

Context::$HTTP_CLIENT_FACTORY = new class() extends HttpClientFactory {
public function client(): ClientInterface
{
// This is the default client, but we need to add the header for presentment prices
return new Client(['headers' => ['X-Shopify-Api-Features' => 'include-presentment-prices']]);
}
};

$hostName = App::parseEnv($pluginSettings->hostName);
$accessToken = App::parseEnv($pluginSettings->accessToken);

Expand Down
Loading