phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

Translations for items #302

Open RWAP opened 1 year ago

RWAP commented 1 year ago

Shopify now appears to support translatable content for products, but I could not see that this is implemented in the code (or how to access it):

https://shopify.dev/docs/api/admin-graphql/2023-07/queries/translatableResource#section-examples

whobutsb commented 11 months ago

I ran in to this issue as well. You need to use the Storefront GraphQL API in order to retrieve the translations. I actually just wrote a PR #308 that allows you to use this library to make requests to the storefront api.

Here is how you would use the PR to get a product translations for french Canadian:

$shopify = \PHPShopify\ShopifySDK::config([
    'AccessToken' => 'SHOPIFY_ADMIN_TOKEN',
    'ShopUrl' => 'my-store.myshopify.com',
    'StoreFrontAccessToken' => 'STOREFRONT_ACCESS_TOKEN'
]);

$query = <<<GQL
    query getProductById(\$id: ID!) @inContext(country: CA, language: FR) {
        product(id: \$id) {
            id
            title
            handle
            productType
            tags
            descriptionHtml
            options {
                id
                name
                values
            }
        }
    }
GQL;
// product global id - 'gid://shopify/Product/123456789'
$variables = [
    'id' => $productGID
];

$data = $shopify->GraphQL->storefront($query, null, null, $variables);