<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
punchout-catalogs / punchout-catalog-spryker example snippets
namespace Pyz\Yves\PunchoutCatalog;
use PunchoutCatalog\Yves\PunchoutCatalog\PunchoutCatalogConfig as BasePunchoutCatalogConfig;
class PunchoutCatalogConfig extends BasePunchoutCatalogConfig
{
/**
* @return array
*/
public function getCustomCartMapping(): array
{
return [
// QuoteTransfer => PunchoutCatalogDocumentCartTransfer
// without key, should return transfer object
function ($quoteTransfer, $cartRequestTransfer, $plugin) {
$cartRequestTransfer->setCoupon('Coupon for ' . $quoteTransfer->getName());
return $cartRequestTransfer;
},
'cart_note' => 'name',
];
}
/**
* @return array
*/
public function getCustomCartItemMapping(): array
{
return [
//ItemTransfer => PunchoutCatalogDocumentCartItemTransfer
'custom_sku' => function($quoteItemTransfer, $documentCartItemTransfer, $quoteTransfer, $plugin) {
return 'here-is-custom-sku-' . $quoteItemTransfer->getAbstractSku();
},
'sale_bunch_quantity' => function($quoteItemTransfer, $documentCartItemTransfer, $quoteTransfer, $plugin) {
//Product #1
if ($quoteItemTransfer->getAbstractSku() === 'any_condition_1') {
return 100;
}
//Product #2
if ($quoteItemTransfer->getAbstractSku() === 'any_condition_2') {
return 50;
}
return 1;
},
'custom_fields' => function($quoteItemTransfer, $documentCartItemTransfer, $quoteTransfer, $plugin) {
return array(
'custom_field_1' => 'quote-item-id=' . $quoteItemTransfer->getId(),
'custom_field_2' => 'custom-abstract-sku-' . $quoteItemTransfer->getAbstractSku(),
'custom_field_3' => 'custom_field_value_3',
'custom_field_4' => 'custom_field_value_4_' . uniqid(),
'custom_field_5' => 'custom_field_value_5_' . uniqid(),
'custom_field_contract' => 'ContractID-'. uniqid(),
'custom_field_org' => 'TestPurchOrg',
'custom_field_ref' => 'some-ref',
//...add as many custom fields as you need and can use in mapping
);
},
/**
* @param \Generated\Shared\Transfer\ItemTransfer
* @param \Generated\Shared\Transfer\PunchoutCatalogDocumentCartItemTransfer
* @param \Generated\Shared\Transfer\QuoteTransfer
* @param \PunchoutCatalog\Yves\PunchoutCatalog\Mapper\CartTransferMapperDefaultPlugin
*/
function ($quoteItemTransfer, $documentCartItemTransfer, $quoteTransfer, $plugin) {
$name = trim($quoteItemTransfer->getName());
$documentCartItemTransfer->setDiscountDescription('Custom discount description for ' . $name);
return $documentCartItemTransfer;
},
'discount_description' => 'name',
'cart_note' => 'group_key',
];
}
/**
* @return array
*/
public function getCustomCartCustomerMapping(): array
{
return [
//CustomerTransfer => PunchoutCatalogDocumentCartCustomerTransfer
'first_name' => 'customer_reference',
/**
* @param \Generated\Shared\Transfer\CustomerTransfer
* @param \Generated\Shared\Transfer\PunchoutCatalogDocumentCustomerTransfer
* @param \Generated\Shared\Transfer\QuoteTransfer
* @param \PunchoutCatalog\Yves\PunchoutCatalog\Mapper\CartTransferMapperDefaultPlugin
*/
function ($quoteCustomerTransfer, $documentCartCustomerTransfer, $quoteTransfer, $plugin) {
return $documentCartCustomerTransfer;
},
];
}
}
namespace Pyz\Yves\Router;
use PunchoutCatalog\Yves\PunchoutCatalog\Plugin\Router\PunchoutCatalogRouteProviderPlugin;
use Spryker\Yves\Router\RouterDependencyProvider as SprykerRouterDependencyProvider;
class RouterDependencyProvider extends SprykerRouterDependencyProvider
{
/**
* @return \Spryker\Yves\RouterExtension\Dependency\Plugin\RouteProviderPluginInterface[]
*/
protected function getRouteProvider(): array
{
return [
new PunchoutCatalogRouteProviderPlugin()
];
}
}
namespace Pyz\Yves\ShopApplication;
use PunchoutCatalog\Yves\PunchoutCatalog\Plugin\Provider\PunchoutCatalogControllerProvider;
use SprykerShop\Yves\ShopApplication\YvesBootstrap as SprykerYvesBootstrap;
class YvesBootstrap extends SprykerYvesBootstrap
{
/**
* @param bool|null $isSsl
*
* @return \SprykerShop\Yves\ShopApplication\Plugin\Provider\AbstractYvesControllerProvider[]
*/
protected function getControllerProviderStack($isSsl)
{
return [
new PunchoutCatalogControllerProvider($isSsl),
];
}
}
namespace Pyz\Zed\Router;
use Spryker\Zed\Router\RouterConfig as SprykerRouterConfig;
class RouterConfig extends SprykerRouterConfig
{
/**
* @return string[]
*/
public function getControllerDirectories(): array
{
$controllerDirectories = parent::getControllerDirectories();
//...
$controllerDirectories[] = sprintf('%s/punchout-catalogs/*/src/*/Zed/*/Communication/Controller/', APPLICATION_VENDOR_DIR);
return array_filter($controllerDirectories, 'glob');
}
}