@blipicodes/medusa-plugin-store-credit v1.0.1
Medusa Store Credit
Give store credit to customers that they can spend in your shop.
Features
- Give store credit to customers that they can spend in your shop.
- Store credit allows customers to make multiple purchases until the credit is exhausted.
- It can be used as a personal refund or compensation card in case there’s a problem with your product or service.
Prerequisites
How to Install
1. Run the following command in the directory of the Medusa backend:
npm i @agilo/medusa-plugin-store-credit2. In medusa-config.js add the following at the end of the plugins array:
const plugins = [
// ...
{
resolve: "@agilo/medusa-plugin-store-credit",
options: {
enableUI: true,
},
},
];3. Run the following command in the directory of the Medusa backend to run the migrations:
npx medusa migrations runTest the Plugin
1. Start your Medusa backend and admin dashboard, eg.:
npm run dev2. Visit Store Credit screen in the admin dashboard to assign store credit to a customer.
3. Implement your storefront.
The plugin extends the storefront Cart, Customer and Order models with store credit information you can use to implement your storefront, eg.:
/store/carts/{id}-cartwill containstore_credit_totalfield which is the total store credit available to be used in that cart/store/customers/me-customerwill containstore_creditsarray with all store credits available per region for the logged in customer/store/customers/me/orders-orderwill containstore_credit_total,store_credit_transactionsandstore_creditswhich were used in the order
An example storefront implementation can be found in https://github.com/Agilo/medusa-plugin-store-credit/tree/master/packages/medusa-storefront
Contributing
We welcome contributions from the community to help make this project even better. Please feel free to open pull requests or issues. Thank you for considering contributing, and we look forward to collaborating with you!
Below you can find the plugin development guide that will help you get started with running Medusa Store Credit in your local environment.
Plugin Development
Prerequisites
Running Locally
Follow these step-by-step instructions to run the project locally:
git clone https://github.com/Agilo/medusa-plugin-store-credit.git- clone the monorepocd medusa-plugin-store-credit- position into the project directorycp .env.example .env- set up docker-compose environment variablesdocker compose up- start Medusa Docker containers- Open a new terminal tab
yarn install && yarn run setup- install dependencies in all packagescd packages/medusa && medusa migrations run && cd ../..- run the migrationscd packages/medusa && yarn run seed:plugin && cd ../..- seed the databaseyarn run start- build the packages and start the Medusa dev server and plugin watcher
Medusa Admin is now available at http://localhost:7001 and Medusa Storefront at http://localhost:8000
Default credentials for Medusa Admin are:
admin@medusa-test.com
supersecretOnce you have the project running locally you can start making changes to the plugin in packages/medusa-plugin-store-credit/src and see them reflected in the Medusa Admin and Storefront.
Generating migrations
Unfortunately DX when generating migrations which extend or relate to core entities is not great, but here's a workflow that works:
yarn run start- make sure workflow is runningcp packages/medusa-plugin-store-credit/.env.example packages/medusa-plugin-store-credit/.env- copy and edit environment variablescd packages/medusa-plugin-store-credit/src/migrations- navigate to the plugin dirnpx typeorm migration:generate -d datasource.js src/migrations/StoreCreditUpdate- this will generate a migration file with a bunch of migrations insrc/migrations/<timestamp>-StoreCreditUpdate.ts, the migration file will contain migrations for both core medusa entities and your plugin entities. You can now cherry pick the migrations you want to run and delete the rest.- In the
packages/medusadir runmedusa migrations run
Available Commands
yarn run setup- install dependencies in all packagesyarn run start- build the packages and start the Medusa dev server and plugin watcheryarn run sync- use yalc to publish and pushmedusa-plugin-store-creditto Medusa backend
Docker Services
Docker services are defined in docker-compose.yml file.
postgres- PostgreSQL database server for Medusa available on localhost:5432, you can change credentials and port in.envandpackages/medusa/.envfilesredis- Redis server for Medusa available on localhost:6379
Additional Resources
License
This project is licensed under the MIT License.
Credits
MedusaWP is developed and maintained by AGILO.
Huge thanks to all contributors.
1 year ago