Components
ReadyProductSelector

ReadyProductSelector

The ReadyProductSelector is a versatile React component designed for your Shopify app. It allows users to browse and select products or variants from their Shopify store, providing a seamless integration with Shopify's resource picker.

Import

import { ReadyProductSelector } from 'path/to/ReadyProductSelector';

Props

PropTypeDefaultDescription
titlestringRequiredThe title displayed at the top of the component
subtitlestring""An optional subtitle for additional context
productsarrayRequiredAn array of selected products
setProductsfunctionRequiredA function to update the selected products
typestring"product"The type of resource to select ("product" or "variant")
multiplebooleanfalseWhether multiple selections are allowed
actionstring"select"The action to perform in the resource picker
filterVariantbooleantrueWhether to filter variants in the selection
childrenReact.ReactNodenullOptional child components to render

Usage

import { useState } from 'react';
import { ReadyProductSelector } from './ReadyProductSelector';
 
function ProductPage() {
  const [selectedProducts, setSelectedProducts] = useState([]);
 
  return (
    <ReadyProductSelector
      title="Select Products"
      subtitle="Choose products to feature"
      products={selectedProducts}
      setProducts={setSelectedProducts}
      multiple={true}
    />
  );
}

Functionality

  1. Product Selection: Users can browse and select products using Shopify's resource picker.
  2. Display Selected Products: Shows selected products with their image, title, and variant information.
  3. Remove Products: Allows users to remove individual products from the selection.
  4. Variant Handling: Can filter and display product variants based on the filterVariant prop.

Component Structure

  • The component is wrapped in a Shopify Polaris Card for consistent styling.
  • It uses various Polaris components like BlockStack, InlineStack, Button, Select, and Thumbnail for layout and UI elements.
  • Selected products are displayed in a list, each within a bordered box.

Notes

  • The component integrates with the shopify.resourcePicker API for product selection.
  • It normalizes the data returned from the resource picker to maintain a consistent structure.
  • The component handles both single and multiple product selections.

Customization

You can customize the appearance and behavior of the ReadyProductSelector by adjusting the props or modifying the component's internal structure. Consider extending the component or wrapping it in a higher-order component for more advanced customizations.