ScandiPWA
Create Magento AppCreate ScandiPWA AppUser ManualGitHub
  • Why Scandi
  • πŸš€Quick-start Guide
  • πŸ—ΊοΈRoadmap
  • Introduction to the Stack
    • CMA, CSA, and ScandiPWA
    • Challenges
  • Setting up Scandi
    • Storefront Mode Setup
      • Proxying requests to server
    • Magento Mode Setup
    • Existing Magento 2 setup
    • Magento Commerce Cloud setup
    • Updating to new releases
      • Storefront mode upgrade
      • Magento mode upgrade
      • CMA upgrade
      • CSA upgrade
      • Custom ScandiPWA composer dependency update
      • Local ScandiPWA Composer Package Setup
    • Docker Setup [deprecated]
      • Legacy Docker setup
      • Migrating to CMA & CSA
  • Developing with Scandi
    • Override Mechanism
      • Overriding JavaScript
        • Overriding classes
        • Overriding non-classes
      • Overriding Styles
      • Overriding the HTML / PHP
      • Parent Themes
    • Extensions
      • Creating an extension
      • Installing an extension
      • Migrating from 3.x to 4.x
      • Publishing an extension
      • Extension Terminology
    • Working With Magento
      • Magento troubleshooting
      • Working with Magento modules
      • Working with GraphQL
      • GraphQL Security
      • Working with "granular cache"
    • Developer Tools
      • Debugging in VSCode
      • ScandiPWA CLI
      • Configuring ESLint
      • CSA Commands
    • Deploying Your App
      • Build & Deploy Android app
      • Build & Deploy iOS app
  • Structure
    • Directory Structure
    • Building Blocks
      • Components
        • Styling Components
      • Routes
      • Redux Stores
      • GraphQL Queries
      • Global Styles
      • The Util Directory
      • Type Checking
    • Application assets
    • Code Style
      • JavaScript Code Style
      • SCSS Code Style
  • Tutorials
    • Customizing Your Theme
      • Styling
        • Customizing the Global Styles
        • Adding a New Font
        • Overriding a Components Styles
        • Extending a Component's Styles
      • Customizing JavaScript
        • Customizing the Footer Copyright
        • Adding a New Page
        • Adding a Section in My Account
        • Adding a Tab on the Product Page
        • Creating a New Redux Store
    • Payment Method Integration
      • Setting Up for Development
      • Redirecting to the Payment Provider
      • Handling the Customer's Return
    • Creating a Custom Widget
      • Scandi CMS System Overview
      • Creating a Magento Widget
      • Implementing the Rendering
    • Video Tutorials
      • #1 Setting up and talking theory
      • #2 Templating in React
      • #3 Overriding a file
      • #4 Styling the application
      • #5 Patterns of ScandiPWA
    • Dark Mode Extension
    • Deploying Native Apps
    • Product 3D Model Extension
      • Part 1: Magento 3D Model Uploads
      • Part 2: GraphQL API
      • Part 3: Scandi Frontend
    • Social Share, Full Extension Development
      • STEP-1 and 2 Creating Magento 2 Module
      • STEP-3 Backend Configurations Settings
      • STEP-4 Simple GraphQl and Resolver
      • STEP-5 Creating Extension, Base Redux Store
      • STEP-6 Extension plugins
      • STEP-7 GraphQL types, Helpers
      • STEP-8 Query Field and FieldList
      • STEP-9 render Plugins and MSTP Plugin, Component creation
      • STEP-10 SocialShare Component Development
      • STEP-11 SocialShare for CategoryPage
      • TASK-1 Changing LinkedIn to Twitter
      • STEP-12 Comments for Admin Users
      • STEP-13 Final, bugfixes
    • Accessing Magento 2 Controllers
      • STEP-1 Creating Magento 2 Module
      • STEP-2 - Create Magento 2 Frontend Route and Basic Controller
      • STEP-3 Accessing Magento 2 Controller, Bypassing ScandiPWA frontend
      • STEP-4 Creating ScandiPWA Extension with additional dependencies
      • STEP-5 Creating Plugin and Axios request
  • About
    • Support
    • Release notes
    • Technical Information
    • Data Analytics
    • Contributing
      • Installation from Fork
      • Repository structure
      • Code contribution process
      • Submitting an Issue
      • Publishing ScandiPWA
Powered by GitBook
On this page
  • β˜‘οΈ Prerequisites
  • πŸ“¦ Installation
  • πŸƒβ€β™€οΈ Running the App
  • πŸ” Quick Tour
  • 🎨 Customizing Your App
  • 🎭 Override Mechanism
  • πŸ”₯ Hot Reload
  • πŸ‘‹ Need Help?
  • πŸš€ Share it With the World!
  • πŸ“ What Next?

Was this helpful?

Quick-start Guide

Get familiar with Scandi in a few minutes!

PreviousWhy ScandiNextRoadmap

Last updated 3 years ago

Was this helpful?

β˜‘οΈ Prerequisites

Make sure you have installed Node v14. We recommend (macOS, Linux) or to easily manage different Node installations. Also, npm should be v6.

Also install the ScandiPWA CLI – it's a command-line tool that will help you work with Scandi much faster:

npm i -g scandipwa-cli

πŸ“¦ Installation

Let's create a new app so we have something to work with! In the terminal, type:

npm init scandipwa-app my-first-app

This will install all required dependencies, and initialize a new Scandi app in my-first-app. Once that has completed, you can take a look at the resulting files:

my-first-app/
β”œβ”€β”€ composer.json
β”œβ”€β”€ i18n/
β”œβ”€β”€ yarn.lock
β”œβ”€β”€ magento/
β”‚Β Β  β”œβ”€β”€ etc/
β”‚Β Β  β”œβ”€β”€ registration.php
β”‚Β Β  └── theme.xml
β”œβ”€β”€ node_modules/        # Dependencies live here
β”œβ”€β”€ package.json         
β”œβ”€β”€ public/
β”œβ”€β”€ README.md
└── src/                 # πŸ” Your code goes here
  • composer.json and the magento directory are needed so that your app can function as a Magento theme

  • package.json specifies certain information about your app - such as its name and the packages it needs to work

  • yarn.lock keeps track of the exact dependency versions you have installed. The dependencies themselves live in node_modules

  • src and public are empty right now - but we will write some code in them!

πŸƒβ€β™€οΈ Running the App

We haven't even written any customization code yet, but the Scandi app can work out of the box!

cd my-first-app/
npm start

Note: the app is only visible to you – nobody on the internet can see your Scandi app at the moment. The npm start command is for working on your app while testing it on your computer, not for production use.

If you browse around, you will see CMS content and products. But you probably don't have an instance of Magento running on your computer, so where is this data coming from?

πŸ” Quick Tour

How come we got a beautiful working app without writing a single line of code? What you see is the "base" Scandi theme. Its code can be found in node_modules/@scandipwa/scandipwa/src/ – it is a dependency of your app. We can take a look inside to get an idea of how it works

node_modules/@scandipwa/scandipwa/src/
β”œβ”€β”€ component/
β”œβ”€β”€ index.js
β”œβ”€β”€ query/
β”œβ”€β”€ route/
β”œβ”€β”€ service-worker.js
β”œβ”€β”€ style/
β”œβ”€β”€ store/
β”œβ”€β”€ type/
└── util/

Here are the most important directories you need to know about:

Directory

Purpose

component

This is where all the individual UI components live. For example, there's the Header and Footer components, which are used on all pages, as well as the CheckoutPayment component, which is only used in the checkout payment step.

Each component has its own UI logic and styling.

route

All the different pages of Scandi are defined here. The cart page, the category page, the home page and many others – each has their own folder inside route. Their job is to bring the different components together to create entire pages.

style

All the "global" styles that apply to the page as a whole (and are not specific to a single component) go here.

🎨 Customizing Your App

The app works, but looks just like any other Scandi app. You probably want to customize some of its features. As a first step, let's customize the copyright footer.

Before we can modify its code, we need to know which component is responsible for rendering the Footer. We can use the browser's developer tools to find out. First, inspect the HTML element associated with the footer:

The developer tools should open, giving you information about the element. The element you selected will appear highlighted:

Now that we have found out the name of the component, there is only one place we need to look – the component directory in node_modules/@scandipwa/scandipwa/src/. Indeed, we can find a component named Footer there:

Original File in scandipwa/src/component/Footer/Footer.component.js
// [...]
export class Footer extends PureComponent {
    // [...]
    
    renderCopyrightContent() {
        const { copyright } = this.props;

        return (
            <ContentWrapper
              mix={ { block: 'Footer', elem: 'CopyrightContentWrapper' } }
              wrapperMix={ { block: 'Footer', elem: 'CopyrightContent' } }
              label=""
            >
                <span block="Footer" elem="Copyright">
                    { copyright }
                    { ' Powered by ' }
                    <a href="https://scandipwa.com">
                        ScandiPWA
                    </a>
                </span>
            </ContentWrapper>
        );
    }

    render() {
        return (
            <footer block="Footer" aria-label="Footer">
                { this.renderContent() }
                { this.renderCopyrightContent() }
            </footer>
        );
    }
}

export default Footer;

Now that we have found the component, we can update its code. But don't edit the file we found in node_modules – modifying dependency code is almost always a bad idea. (It would be hard to get updates, and difficult to track which of the many files you have edited). Instead, let's override it.

🎭 Override Mechanism

Scandi offers a great way to customize any component, and its called the Override Mechanism. With the override mechanism, you can override any file you want, while keeping the default implementations for the other files. This gives you great flexibility without having to duplicate any code.

To override a file, you need to create a new file with the same path in your src directory. For example...

To override:
    component/Footer/Footer.component.js
    (in node_modules/@scandipwa/scandipwa/src/)

...you need to create a new file:
    component/Footer/Footer.component.js
    (in src/)
scandipwa override component Footer

When you run that command, the Scandi tool will ask you which components you want to override. Select the Footer class in Footer.component.js; leave the other fields blank:

Now we have created the file, which overrides the original Footer component file. Now, we want to import the original class, so that we can keep most of the Footer functionality, and extend it to customize its behavior:

File override in src/component/Footer/Footer.component.js
// We will need the ContentWrapper component later - let's import it
import ContentWrapper from 'Component/ContentWrapper';


// Import the original class (we want to keep most of the functionality)
// Note that we are using the "SourceComponent" alias in the import path –
// This tells Scandi that we want to get the original Footer component
import {
    Footer as SourceFooter
} from 'SourceComponent/Footer/Footer.component';


// Extend the original class (SourceFooter)
// By subclassing it, we can change some of its behavior
/** @namespace myFirstApp/Component/Footer/Component/FooterComponent */
export class FooterComponent extends SourceFooter {

    // This is the function responsible for rendering copyright
    // We want to change it, so we re-define in this subclass
    renderCopyrightContent() {
    
        // Changed:
        // Instead of the copyright text, let's write a friendly message
        return (
            <ContentWrapper
              mix={ { block: 'Footer', elem: 'CopyrightContentWrapper' } }
              wrapperMix={ { block: 'Footer', elem: 'CopyrightContent' } }
              label=""
            >
                <span block="Footer" elem="Copyright">
                    Thank you for visiting my website. You are amazing!
                </span>
            </ContentWrapper>
        );
    }
    
    // All the other functions will stay the same...
    // Because we didn't override any other default functionality
}

// All components, including the original Footer component, have a
// default export. Other files use this export when they want to use
// this component.
// Now, instead of providing the original component, we export our
// overridden component. Any file importing this will get the new behavior!
export default FooterComponent;

πŸ”₯ Hot Reload

Scandi implements hot reload – which means that you don't need to compile the app again. Just check your browser and the changes should have appeared.

Congratulations! Now you understand the basics of file overriding – and you can override any file in the app to change its behavior.

πŸ‘‹ Need Help?

πŸš€ Share it With the World!

Now you have your very own Scandi app. Let's deploy so you can brag about it πŸ˜‚ – all it takes is one command:

scandipwa deploy

The Scandi CLI will do its magic, and give you the URL of your deployed app. You can check if your updated message is in the Footer – it should still be there, but this time, accessible to anyone on the internet!

πŸ“ What Next?

Now that you know the basics of working with Scandi, you can explore the rest of the ecosystem. What you choose to do will depend on your needs and is entirely up to you:

  • Want to improve your workflow? Check out our recommended development environment.

  • Get a more in-depth understanding of Scandi's structure

The start command will run your app at and open it in the browser.

By default, scandipwa-app is configured to to a remote Magento instance. There are of course other configurations available, but we'll stick with the proxy for the purposes of this guide – its the fastest to set up.

Known issue: If you come across an iframe covering the entire screen when starting ScandiPWA app, please check here:

Note the class of the element you found. This might be slightly different depending on where you clicked – in our case, it is Footer-Copyright. What does this tell us about the component? Because Scandi follows strict conventions, this gives us the name of the component – Footer (the first part of the class, called the Block, is always the same as the component name).

That funny . Scandi uses the React library to render its user interface, and JSX is the easiest way to use React.

Instead of manually creating a new file, you can save yourself a lot of time by using the . With a single command, you can override the Footer component:

If you get stuck or have any questions, we'd be happy to help! Feel free to drop us a message in – all tech-related questions are welcome in the #pwa-tech channel.

Want some more hands-on experience? Stop by our !

Learn about – plugins you can easily install to get additional functionality

Want a working Magento backend to go with your app? Try !

πŸš€
n
nvm-windows
http://localhost:3000/
forward all requests
https://stackoverflow.com/questions/69051008/react-injecting-iframe-with-max-z-index-on-reload-after-changes-development
HTML-in-JavaScript syntax is called JSX
Scandi CLI
Slack
tutorial section
extensions
create-magento-app
What you should see
Using the Scandi CLI to override the Footer component
πŸŽ‰πŸŽ‰
Deploying the app
Block-Element-Modifier (BEM)