Git Product home page Git Product logo

torys877 / crypto-magento-nftloyalty Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 3.33 MB

Magento 2 NFT Loyalty Extension. It allows to use NFT token as 'Discount Card' for implementing NFT Loyalty Programs.

License: MIT License

PHP 74.74% Solidity 0.70% TypeScript 1.70% HTML 5.40% JavaScript 17.47%
magento magento2 magento2-extension magento2-module nft nftloyalty nft-loyalty blockchain erc721 ethereum

crypto-magento-nftloyalty's Introduction

Crypto NftLoyalty Magento 2 Extension

Magento 2 NFT Loyalty Extension Allows to use NFT token as 'Discount Card' for implementing NFT Loyalty Programs.

Description

Extension adds new condition for Magento 2 Cart Rules functional and checks if customer has tokens of specified NFTs in wallet.

If NFT tokens are presented in wallet - it applies discount follow rules that are set in Magento Cart Rules.

Extension allows to implement discount programs, partnership program, NFT loyalty programs between magento stores and web3 projects.

For frontend actions module uses Metamask and web3.js, for backend checks - modified web3.php library.

How It Works

Customer can apply NFT on cart page and on checkout page too.

  • Customer connect own wallet to website and press Apply NFT.
  • Customer wallet address is sent to backend and saving to Quote table.
  • After saving, Magento gets all NFTS from NFT table and check whether customer has any or several from that NFTs by calling balanceOf on NFTs smart contract
  • If customer has NFTs from NFT table, found NFT are saved in separate table
  • Magento recalculate totals (run collectTotals after applying NFT)
  • During collecting totals, Magento runs sales rule total that runs NFT rule and apply Cart Rule if it fits
  • Magento updates Summary (totals) sections on frontend for outputting discount for customer

Installation

Add PHP Web3 Repository

PHP Web3 library uses old version of phpseclib (v2), but magento requires version 3. It was changed in web3 fork thus you need to add custom repository for web3.php.

        "web3p/web3.php": {
            "type": "git",
            "url": "[email protected]:torys877/web3.php.git"
        }

Composer Installation

composer require cryptom2/magento-nftloyalty:v1.0.0

Magento Run

php bin/magento setup:upgrade

Hardhat install for testing

Hardhat allows you to run local ethereum network, deploy demo NFT and test module locally.

Go To:

{project_folder}/vendor/cryptom2/magento-nftloyalty/hardhatnft

Run:

npm install --save-dev hardhat

npx hardhat node

npx hardhat run --network localhost ./scripts/deploy.ts

After that commands you should see NFT token address for demo test and hardhat default account, that can be integrated in Metamask.

Features

Menu Under Marketing Section

Menu

Adding New NFT

  • NFT Name - will be used in Cart Rules in admin area for selection NFT (later, for output on frontend to show which NFT was applied exactly)
  • NFT Contract Abi - not used now, will be used later if NFT needs some custom functional
  • NFT Symbol - will be used later or instead of NFT Name
  • NFT Address - address of NFT, Magento checks customer NFT balance using this NFT address

New NFT

Configuration

  • Enabled - enable/disable functional
  • RPC Endpoint - endpoint
  • NFT Smart Contract ABI - Default JSON ABI for NFT smartcontract. Now there is using only 1 function balanceOf

Configuration

Apply NFT Section on Cart Page

Cart Page0

Cart Page1

Cart Page2

Apply NFT Section on Checkout Page

Checkout Page1

Checkout Page2

Adding Sales Rule With NFT Condition

Sales Rule

TODO

Now the extension has base functional and checks only if customer has or no NFT in wallet. But it has much more potential in future.

Here are several TODOs that are going to be implemented later:

  • add checking NFT tokens amount and apply discount based on how many NFTs customer has (now it checks only balanceOf greater than zero or no)
  • output NFT name, rule name or NFT symbol on checkout and cart pages, to show what NFT was applied for discount
  • send customer wallet and some data as signed message from frontend to backend during applying NFT (for security)
  • mint NFT for customer depending on some conditions (order grand total or amount of purchases in the store)
  • output customer wallets(accounts) to choose which should be assigned to website or which should be used for NFT applying.
  • implement some kind of NFT interface to keep Discount Rules inside NFTs smart contract and apply them in Magento
  • feel free to fork and fix/implement anything if you are interested

Author

Ihor Oleksiienko

License

Magento NFT Loyalty extension for Magento 2 is licensed under the MIT License - see the LICENSE file for details

crypto-magento-nftloyalty's People

Contributors

torys877 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.