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

Was this helpful?

  1. Tutorials
  2. Social Share, Full Extension Development

STEP-5 Creating Extension, Base Redux Store

In this step finally, we going to begin scandipwa extension development

PreviousSTEP-4 Simple GraphQl and ResolverNextSTEP-6 Extension plugins

Last updated 3 years ago

Was this helpful?

  1. Create scandipwa extension using scandipwa-cli, for that navigate to your theme folder, and execute scandipwa extension create scandipwa-socialshare

  2. In your scandipwa theme packages folder you should locate scandipwa-socialshare extension folder NOTE. In my case ONLY for development purposes extension is located right in Magento module so my scandipwa/package.json file looks like

"dependencies": {
   "@scandipwa/scandipwa": "4.4.0",
   "scandipwa-socialshare": "file:../app/code/ScandiPWA/SocialShareGraphQl/scandipwa-socialshare"
},
"scandipwa": {
   "type": "theme",
   "locales": {
       "en_US": true
   },
   "parentTheme": "@scandipwa/scandipwa",
   "extensions": {
       "scandipwa-socialshare": true
   }
},

Your file should look like so.

"dependencies": {
   "@scandipwa/scandipwa": "4.4.0",
   "scandipwa-socialshare": "file:packages/scandipwa-socialshare"
},
"scandipwa": {
   "type": "theme",
   "locales": {
       "en_US": true
   },
   "parentTheme": "@scandipwa/scandipwa",
   "extensions": {
       "scandipwa-socialshare": true
   }
},

3. First, let’s create a query that going to query graph that we created in STEP-4 create query folder in scandipwa-socialshare/src <- (in future <SOURCE>) and SocialShare.query.js in it

scandipwa-socialshare/src/query/SocialShare.query.js
import { Field } from 'Util/Query';

/** @namespace ScandipwaSocialshare/Query/SocialShare/Query/SocialShareQuery */
export class SocialShareQuery {
   getQuery() {
       return new Field('socialShare')
           .addFieldList(['enabled']);
   }
}

export default new SocialShareQuery();

4. Now we going to create the SocialShare redux store, create store folder in <SOURCE>/ and SocialShare folder in <SOURCE>/store/

5. In <SOURCE>/store/SocialShare create SocialShare.action.js

scandipwa-socialshare/src/store/SocialShare/SocialShare.action.js
export const UPDATE_SOCIAL_SHARE = 'UPDATE_SOCIAL_SHARE';

/** @namespace Store/SocialShare/Action/updateSocialShare */
export const updateSocialShare = (socialShare) => ({
   type: UPDATE_SOCIAL_SHARE,
   socialShare
});

6. In <SOURCE>/store/SocialShare create SocialShare.reducer.js

scandipwa-socialshare/src/store/SocialShare/SocialShare.reducer.js
import { UPDATE_SOCIAL_SHARE } from './SocialShare.action';

/** @namespace ScandipwaSocialshare/Store/SocialShare/Reducer/getInitialState */
export const getInitialState = () => ({
   socialShare: {
       enabled: 'not'
   }
});

/** @namespace ScandipwaSocialshare/Store/SocialShare/Reducer/SocialShareReducer */
export const SocialShareReducer = (
   state = getInitialState(),
   action
) => {
   const {
       type,
       socialShare
   } = action;

   switch (type) {
   case UPDATE_SOCIAL_SHARE:
       return {
           ...state,
           ...socialShare
       };

   default:
       return state;
   }
};

export default SocialShareReducer;

7. And finally in <SOURCE>/store/SocialShare create SocialShare.dispatcher.js

scandipwa-socialshare/src/store/SocialShare/SocialShare.dispatcher.js
import { showNotification } from 'Store/Notification/Notification.action';
import BrowserDatabase from 'Util/BrowserDatabase';
import { QueryDispatcher } from 'Util/Request';
import { ONE_MONTH_IN_SECONDS } from 'Util/Request/QueryDispatcher';

import SocialShareQuery from '../../query/SocialShare.query';
import { updateSocialShare } from './SocialShare.action';

/** @namespace ScandipwaSocialshare/Store/SocialShare/Dispatcher/SocialShareDispatcher */
export class SocialShareDispatcher extends QueryDispatcher {
   __construct() {
       super.__construct('SocialShare');
   }

   onSuccess(data, dispatch) {
       if (data) {
           BrowserDatabase.setItem(data, 'SocialShare', ONE_MONTH_IN_SECONDS);
           dispatch(updateSocialShare(data));
       }
   }

   onError(error, dispatch) {
       dispatch(showNotification('error', __('Error fetching SocialShare!'), error));
   }

   prepareRequest() {
       return [
           SocialShareQuery.getQuery()
       ];
   }
}

export default new SocialShareDispatcher();

Unfortunately on this step, we can't see any visual outcome, the only thing that you can do, is to restart your frontend and ensure that it is still functional, believe in the next step we will have much more fun)).

STEP-5