• Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue Storefront 2 integration for Magento 2
  

Stay connected

GitHub Repo stars Twitter Follow YouTube Channel Subscribers Discord

This repository contains integration for Magento 2 and Vue Storefront Middleware. This integration is framework-agnostic and may be consumed in the framework of your choice.

Magento 2 integration for Vue Storefront

This project is a Magento 2 integration for Vue Storefront.

Check out the docs

Quick start

Your Vue Storefront application has two parts:

  1. Server Middleware - an Express.js application that can connect to your various third-party services (like Magento).

  2. Front-end application - any application using JavaScript or TypeScript that can connect to the server middleware. Popular choices include Nuxt and Next.js.

In this section, we will explain in a step-by-step guide how to use Magento 2 integration in each part of your Vue Storefront application.

Prerequisites

  • Magento configured - you need a Magento 2 configured
  • Install Node.js version >=16.0

Server Middleware

The first step to setup your integration is to create and configure your server middleware layer to connect to your Magento 2 backend.

Already have the server middleware configured? If you have the server middleware configured, you can move directly to the sdk preparation section.

  1. Install the dependencies needed to create your server middleware and to create a server-to-server connection with the Magento 2 backend and the server middleware.
yarn add @vue-storefront/middleware @vue-storefront/magento-api

# npm install @vue-storefront/middleware @vue-storefront/magento-api

# pnpm install @vue-storefront/middleware @vue-storefront/magento-api
  1. Create a file middleware.config.js with server middleware configuration.
// middleware.config.js

import {config} from "dotenv";

config();

const cookieNames = {
  currencyCookieName: 'vsf-currency',
  countryCookieName: 'vsf-country',
  localeCookieName: 'vsf-locale',
  cartCookieName: 'vsf-cart',
  customerCookieName: 'vsf-customer',
  storeCookieName: 'vsf-store',
  messageCookieName: 'vsf-message'
};

export const integrations = {
  magento: {
      location: '@vue-storefront/magento-api/server',
      configuration: {
        api: process.env.VSF_MAGENTO_GRAPHQL_URL,
        cookies: {
          ...cookieNames,
        },
        cookiesDefaultOpts: {
          httpOnly: process.env.VSF_COOKIE_HTTP_ONLY || false,
          secure: process.env.VSF_COOKIE_SECURE || false,
          sameSite: process.env.VSF_COOKIE_SAME_SITE || 'lax',
          path: process.env.VSF_COOKIE_PATH || '/',
        },
        defaultStore: 'default',
        customApolloHttpLinkOptions: {
          useGETForQueries: true,
        },
        magentoBaseUrl: process.env.VSF_MAGENTO_BASE_URL,
        magentoApiEndpoint: process.env.VSF_MAGENTO_GRAPHQL_URL,
        imageProvider: process.env.NUXT_IMAGE_PROVIDER,
        recaptcha: {
          isEnabled: process.env.VSF_RECAPTCHA_ENABLED === 'true',
          sitekey: process.env.VSF_RECAPTCHA_SITE_KEY,
          secretkey: process.env.VSF_RECAPTCHA_SECRET_KEY,
          version: process.env.VSF_RECAPTCHA_VERSION,
          score: process.env.VSF_RECAPTCHA_MIN_SCORE,
        },
        customer: {
          customer_create_account_confirm: true,
        },
      },
    }
};
  1. Configure environment variables in your .env file.
# .env

VSF_NUXT_APP_ENV=production
VSF_NUXT_APP_PORT=3000
VSF_NUXT_APP_HOST=0.0.0.0

VSF_STORE_URL=
API_BASE_URL=
API_SSR_BASE_URL=

VSF_MAGENTO_BASE_URL=
VSF_MAGENTO_GRAPHQL_URL=

NUXT_IMAGE_PROVIDER=ipx

  1. Create a middleware.js file. This script is used to run the server middleware.
// middleware.js

import {createServer} from "@vue-storefront/middleware";
import {integrations} from "./middleware.config.js";
import cors from 'cors';

(async () => {
  const app = await createServer({ integrations });
  const host = process.argv[2] ?? "0.0.0.0";
  const port = process.argv[3] ?? 8181;
  const CORS_MIDDLEWARE_NAME = "corsMiddleware";

  const corsMiddleware = app._router.stack.find(
    (middleware) => middleware.name === CORS_MIDDLEWARE_NAME
  );

  corsMiddleware.handle = cors({
    origin: [
      "http://localhost:3000",
      ...(process.env.MIDDLEWARE_ALLOWED_ORIGINS?.split(",") ?? []),
    ],
    credentials: true,
  });

  app.listen(port, host, () => {
    console.log(`Middleware started: ${host}:${port}`);
  });
})();
  1. Your middleware is ready. You can start it by running node middleware.js. Most likely, you'll want to setup this command as a script in your package.json file.
{
  // ...
  "scripts": {
    "start": "node middleware.js"
  }
  // ...
}

Configuring the SDK

Now, let's configure the SDK in the frontend part of your application to communicate with the server middleware.

  1. Install the SDK package and the Magento 2 module. These packages will allow you to create an instance of the SDK and then extend it with methods to communicate with Magento 2 via your server middleware.
yarn add @vue-storefront/sdk @vue-storefront/magento-sdk

# npm install @vue-storefront/sdk @vue-storefront/magento-sdk

# pnpm install @vue-storefront/sdk @vue-storefront/magento-sdk
  1. Initialize the SDK. Configure Magento 2 module with apiUrl that points to the server middleware.
import { buildModule, initSDK } from '@vue-storefront/sdk';
import { magentoModule, MagentoModuleType } from '@vue-storefront/sdk/magento-sdk';

const sdkConfig = {
  magento: buildModule<MagentoModuleType>(magentoModule, {
    apiUrl: 'http://localhost:8181/magento'
  })
};

export const sdk = initSDK<typeof sdkConfig>(sdkConfig);
  1. Your SDK is ready! You can now import it in the different parts of your frontend application and call methods with sdk.magento.<METHOD_NAME>. To see a full list of methods offered by the Magento 2 module, check out the API Reference.

For example, we can call the products method to fetch products from Magento 2.

import { sdk } from './sdk';
const products = await sdk.magento.products({})
// returns ProductInterface[]

All Contributors

How to start if you want to contribute?

Want to contribute? Ping us on magento2 channel on our Discord!

Requirements:

  • NodeJS v16 or later
  • Yarn (npm is not supprted yet)
  • Magento >= v2.4.3 instance for GraphQL endpoint
  • Change Magento GraphQL Query Complexity and Depth values

Don't forget to change the Magento GraphQL Query Complexity and Depth values Magento 2 by default has a lower value for the complexity of 300, and a higher value for the depth of 20. Magento 2 - Issue #32427

The changes are required, due to the size of the queries and mutations in the api-client implementation.

To do this changes, you can use the Magento 2 module, which adds a configuration panel to your admin, or do this changes manually.

To install the Magento 2 GraphQL Config module, on your Magento installation execute:

composer require caravelx/module-graphql-config

php bin/magento module:enable Caravel_GraphQlConfig

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

Find more information about the module GraphQl Custom Config

Steps

  1. Build dependencies yarn build
    yarn build
  2. Run yarn dev. You can find other commands in package.json
    yarn dev

Resources

Support

If you have any questions about this integration we will be happy to answer them on magento2-vsf2 channel on our Discord.

Contributors

Honorable Mentions

Thanks go to these wonderful people 🙌:


Heitor Ramon Ribeiro

💻 🚧 📖 📆

Alef Barbeli

💻 📖

Henrique Lopes

💻 📖

Đại Lộc Lê Quang

💻

Bogdan Podlesnii

💻

Patrick Monteiro

💻

Kevin Gorjan

💻 📖

Bartosz Herba

💻 📖 🚧 🧑‍🏫 👀

Marcin Kwiatkowski

💻 📆 💼 📖 🤔 🚧 🧑‍🏫 👀

Filip Rakowski

💬 🧑‍🏫 👀

Filip Sobol

💬 🧑‍🏫 👀 📖

Patryk Andrzejewski

💬 🧑‍🏫 👀

Renan Oliveira

🔧 🔌

Dominik Deimel

💻 📖

Lior Lindvor

💻

Artur Tagisow

💻 💬 🤔 🚇 🚧 👀 ⚠️ 🔧

Jonathan Ribas

💻

Ali Ghanei

💻

Maya Shavin

📖

Alexander Devitsky

💻

Diego Alba

💻

Abdellatif EL MIZEB

💻

Beniamin Sinca

🐛 💻

maaarghk

💻

Shankar Konar

💻

Bratuniak Oleg

🐛

Drew Michael

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
TypeScript
10,628
star
2

storefront-ui

A frontend library for Vue and React that helps developers quickly build fast, accessible, and beautiful storefronts. Made with 💚 by Vue Storefront team and contributors.
TypeScript
2,330
star
3

vue-storefront-api

Vue.js storefront for Magento2 (and not only) - data backend
JavaScript
347
star
4

shopware-pwa

Shopware PWA for eCommerce. Headless storefront solution for Shopware 6, which communicates through the SalesChannel-API. Always Open Source, MIT license. Made with 💙 by shopware AG & Vue Storefront.
TypeScript
345
star
5

mage2vuestorefront

Magento to Vue-storefront datapump - synchronizes Products, Categories and Product-to-category links between your Magento2 API and NoSQL database of vue-storefront
JavaScript
199
star
6

vsf-capybara

Capybara is a Storefront UI based theme for Vue Storefront. Always Open Source, MIT license. Made with 💚 by Vue Storefront.
Vue
154
star
7

shopify

Vue Storefront 2 integration for Shopify
TypeScript
149
star
8

magento2-vsbridge-indexer

This is official Vue Storefront, native, Magento2 indexer
PHP
69
star
9

ecommerce-integration-boilerplate

Boilerplate for creating new integrations for Vue Storefront Next - open-source frontend for any eCommerce
TypeScript
62
star
10

magento2-rest-client

Magento2 Node.js Rest client
JavaScript
56
star
11

storefront-nuxt3-boilerplate

Nuxt 3 Storefront Boilerplate
Vue
52
star
12

awesome-vuestorefront

😎 A curated list of awesome things related to Vue Storefront 😎
32
star
13

storefront-next13-boilerplate

Vue Storefront Next 13 Boilerplate
TypeScript
26
star
14

vsf-default

Vue Storefront Default theme. Always Open Source, MIT license. Made with 💚 by Vue Storefront. (please consider vsf-capybara instead)
Vue
20
star
15

vue-storefront-1

The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Newest updates: https://blog.vuestorefront.io. Always Open Source, MIT license.
TypeScript
18
star
16

template-shopify

Vue
16
star
17

salesforce-commerce-cloud

Vue Storefront 2 integration for Salesforce Commerce Cloud
TypeScript
16
star
18

nuxt3-magento-sdk-storefront

A boilerplate storefront build with the Vue Storefront Magento 2 Integration and Storefront UI
JavaScript
15
star
19

integration-boilerplate

Framework Independent boilerplate containing SDK and API Client starters.
TypeScript
14
star
20

template-magento

TypeScript
14
star
21

storefront-nuxt2-magento2

Magento2 Integration for Vue Storefront 2
TypeScript
13
star
22

storyblok

MOVED TO https://github.com/vuestorefront/vue-storefront/tree/legacy/packages/storyblok
TypeScript
12
star
23

developer.vuestorefront.io

Vue Storefront Developer Portal
TypeScript
9
star
24

theme-utilities

Simple theme inheritance for any JavaScript application
TypeScript
8
star
25

sfui2

TypeScript
8
star
26

storefront-api

Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
TypeScript
8
star
27

storefront-query-builder

ElasticSearch Query builder from the abstract "SearchQuery" object used by storefront-api, vue-storefront-api and vue-storefront projects
TypeScript
7
star
28

cli-integrations

List of CLI's integrations and GitHub Actions to manage them.
JavaScript
4
star
29

bigcommerce

TypeScript
4
star
30

nuxt-sdk-playground

Vue
4
star
31

slidev-theme-vuestorefront

Vue
3
star
32

redis-driver

MOVED to https://github.com/vuestorefront/vue-storefront/tree/legacy/packages/redis-driver
JavaScript
3
star
33

vsf-utilities

Vue Storefront shared utilities
TypeScript
2
star
34

payment-template

JavaScript
2
star
35

checkout-com

MOVED TO https://github.com/vuestorefront/enterprise
TypeScript
2
star
36

eslint-config

JavaScript
2
star
37

template-commercetools

Vue
2
star
38

storefront-playground

TypeScript
2
star
39

vuepress-theme-vsf-docs

Vue
1
star
40

next-sdk-playground

Nuxt playground template for SDK integration boilerplate
TypeScript
1
star
41

integration-team-nginx-reverse-proxy

Nginx reverse-proxy dockerfile for the local multistore setup
1
star
42

integrations-github-workflows

1
star