Skip to content

wambo-co/module-catalog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());
}

About

A product catalog module for Wambo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages