Skip to content

Instantly share code, notes, and snippets.

View adevinwild's full-sized avatar
🤍
Cooking with Medusa 2.x

Adil adevinwild

🤍
Cooking with Medusa 2.x
View GitHub Profile
@adevinwild
adevinwild / pricing.ts
Created July 4, 2025 21:30
Based on a Medusa Discord community thread; PoC to make tiered prices works in Medusa V2.8.6 by overriding the PricingModule;
import {
flattenObjectToKeyValuePairs,
isPresent,
MedusaError,
MikroOrmBase,
PriceListStatus,
} from "@medusajs/framework/utils"
import {
BigNumberInput,
@adevinwild
adevinwild / route.ts
Created June 7, 2025 12:31
Learn how to create an order programmatically using Medusa.js V2
// src/api/admin/custom/orders/route.ts
import { createOrderWorkflow } from '@medusajs/core-flows'; // ℹ️ This is the worflow exposed and used inside Medusa
import { type MedusaRequest, type MedusaResponse } from '@medusajs/framework/http';
export async function POST(req: MedusaRequest, res: MedusaResponse) {
// ℹ️ You can use the body of the request to have an Admin API route to handle this
// on top of using modules to fetch dynamically the data (region, items etc...)
// For the demo, we're going to keep it simple with some hardcoded values
const { result } = await createOrderWorkflow(req.scope)
@adevinwild
adevinwild / index.ts
Created May 16, 2025 11:27
Learn how to compute custom shipping price based on Cart Items
import CustomFulfillmentService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default ModuleProvider(Modules.FULFILLMENT, {
services: [CustomFulfillmentService],
})
@adevinwild
adevinwild / extend-validator.ts
Created July 30, 2024 11:54
A new way to extend core validators in Medusa v1.x
import { registerOverriddenValidators } from '@medusajs/medusa'
import { type Constructor } from '@medusajs/types'
type DecoratorFunction = MethodDecorator | PropertyDecorator
type ExtensionDefinition = {
[key: string]: DecoratorFunction | DecoratorFunction[]
}
function extendValidator<Base extends Constructor<any>>(
@adevinwild
adevinwild / product.ts
Created June 28, 2024 10:09
An implementation of the RedisCacheService on the ProductService for Medusa 1.20.x
import type RedisCacheService from '@medusajs/cache-redis/dist/services/redis-cache';
import { ProductService as MedusaProductService, Product } from '@medusajs/medusa';
import { CreateProductInput, FindProductConfig, ProductSelector, UpdateProductInput } from '@medusajs/medusa/dist/types/product';
import type { Redis } from 'ioredis';
type InjectedDependencies = {
cacheService: RedisCacheService
redisClient: Redis
}
@adevinwild
adevinwild / file-upload.tsx
Last active March 7, 2024 10:39
A simple and reusable file upload component made for React with TailwindCSS
import { useRef, useState, type ChangeEvent, type DragEvent } from "react";
import { cn } from "~/lib/utils";
type FileUploadProps = {
onUpload?: (_files: File[]) => void;
accept: string[];
error?: string;
className?: string;
multiple?: boolean;
text?: React.ReactElement | string;
@adevinwild
adevinwild / tailwind.config.js
Created February 26, 2024 14:28
Animated your icons SVGs with a simple keyframe
/** @type {import('tailwindcss').Config} */
export default {
// Other values...
theme: {
extend: {
keyframes: {
svg: {
from: {
strokeDasharray: "1000",
strokeDashoffset: "1000",
@adevinwild
adevinwild / animated-number-display.tsx
Last active February 26, 2024 10:24
An animated number made with Framer Motion and TailwindCSS
import { memo, useEffect, useRef, useState } from 'react'
import { useAnimate } from 'framer-motion'
import { cn } from '~/utils/cn'
/**
* @name AnimatedNumberDisplay
* @description A component that animates a number from an initial value to a new value
*
* @param {Object} props - The options for the component
* @param {string | number} props.initialValue - The initial value of the number
@adevinwild
adevinwild / stepper.tsx
Created February 22, 2024 20:19
A simple Stepper made with TailwindCSS, you'll need `tailwind-merge` and `clsx` (`cn` function we can found for example inside `shadcn/ui`)
"use client";
import React, {
Fragment,
createContext,
useContext,
type HTMLAttributes,
type ReactNode,
} from "react";
@adevinwild
adevinwild / scroll-area.tsx
Last active June 6, 2025 15:59
A shadcn/ui like scroll area that adds a little gradient inside the list with TailwindCSS
import clsx from "clsx";
import {
useEffect,
useRef,
useState,
type HTMLAttributes,
type ReactNode,
type RefObject,
} from "react";