PHP code example of mothership-ec / cog-mothership-commerce

1. Go to this page and download the library: Download mothership-ec/cog-mothership-commerce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mothership-ec / cog-mothership-commerce example snippets


$services->extend('product.page_mapper', function($mapper, $c) {
	$mapper->setValidFieldNames('product');

	// Passing an array to either method will match against all values
	$mapper->setValidGroupNames(['product', 'showcase']);

	// Passing false to the group name will exclude pages within any group
	$mapper->setValidGroupNames(false);

	// Passing null or an empty array to the group name will match pages with
	// any or no group
	$mapper->setValidGroupNames([]);

	$mapper->setValidPageTypes(['product', 'strap']);

	return $mapper;
});

// Find a page from a product
$page = $services['product.page_mapper']->getPageForProduct($product);

// Find a product from a page
$product = $services['product.page_mapper']->getProductForPage($page);

$services['product.page_mapper'] = $services->raw('product.page_mapper.option_criteria');

// Find all pages from a product
$pages = $services['product.page_mapper']->getPagesForProduct($product, ['colour' => 'red']);

// Find a page from a unit
$page = $services['product.page_mapper']->getPageForProductUnit($unit);

// Find units from a page
$units = $services['product.page_mapper']->getProductUnitsForPage($page);

$services->extend('product.page_mapper', function($mapper, $c) {
	$mapper->addFilter(function($obj) {
		if ($obj instanceof Page) {
			return (false !== stristr($obj->title, "foo"));
		}
	});

	return $mapper;
});