Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 2.08 KB

README.md

File metadata and controls

57 lines (42 loc) · 2.08 KB

Wambo Catalog

A product catalog module for Wambo

Build Status Scrutinizer Code Quality Code Coverage

Wambo Catalog provides read access to JSON-based product catalogs.

see: sample-catalog.json

Installation

composer require wambo/module-catalog

Usage

see: examples/usage.php

use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Wambo\Catalog\CachedProductRepository;
use Wambo\Catalog\Mapper\ContentMapper;
use Wambo\Catalog\Mapper\ProductMapper;
use Wambo\Catalog\Model\Product;
use Wambo\Catalog\ProductRepository;
use Wambo\Core\Module\JSONModuleStorage;

// catalog storage
$sampleCatalogFilename = "sample-catalog.json";
$testResourceFolderPath = realpath(__DIR__ . '/catalog');
$localFilesystemAdapter = new Local($testResourceFolderPath);
$filesystem = new Filesystem($localFilesystemAdapter);
$storage = new JSONModuleStorage($filesystem, $sampleCatalogFilename);

// product mapper
$contentMapper = new ContentMapper();
$productMapper = new ProductMapper($contentMapper);

// create the product repository
$productRepository = new ProductRepository($storage, $productMapper);

// create a cached version of the product repository
$cache = new Stash\Pool();
$cachedProductRepository = new CachedProductRepository($cache, $productRepository);

// get the products from the cached repository
$products = $cachedProductRepository->getProducts();

// print the product titles
foreach ($products as $product) {
    /** @var Product $product */
    echo sprintf("%s (SKU: %s)\n", $product->getTitle(), $product->getSku());
}