Marketplace Product + Cart feature integration

Edit on GitHub
You are browsing a previous version of the document. The latest version is 202204.0.

This document describes how to integrate the Marketplace Product + Cart feature into a Spryker project.

Install feature core

Follow the steps below to install the Marketplace Product + Cart feature core.

Prerequisites

To start feature integration, integrate the required features:

NAME VERSION INTEGRATION GUIDE
Spryker Core 202108.0 Spryker Core feature integration
Marketplace Product 202108.0 Marketplace Product feature integration
Cart 202108.0 Cart Feature Integration

1) Set up transfer objects

Generate transfer changes:

console transfer:generate
Verification

Make sure that the following changes have been applied in transfer objects:

TRANSFER TYPE EVENT PATH
Item.merchantReference property Created src/Generated/Shared/Transfer/ItemTransfer

2) Set up behavior

Enable the following behaviors by registering the plugins:

PLUGIN DESCRIPTION PREREQUISITES NAMESPACE
MerchantProductCartPreCheckPlugin Validates that merchant references in the cart items match existing marketplace products. Spryker\Zed\MerchantProduct\Communication\Plugin\Cart
MerchantProductPreAddToCartPlugin Sets merchant reference to item transfer on add to cart. SprykerShop\Yves\MerchantProductWidget\Plugin\CartPage

src/Pyz/Zed/Cart/CartDependencyProvider.php

<?php

namespace Pyz\Zed\Cart;

use Spryker\Zed\Cart\CartDependencyProvider as SprykerCartDependencyProvider;
use Spryker\Zed\Kernel\Container;
use Spryker\Zed\MerchantProduct\Communication\Plugin\Cart\MerchantProductCartPreCheckPlugin;

class CartDependencyProvider extends SprykerCartDependencyProvider
{
    /**
     * @param \Spryker\Zed\Kernel\Container $container
     *
     * @return array<\Spryker\Zed\CartExtension\Dependency\Plugin\CartPreCheckPluginInterface>
     */
    protected function getCartPreCheckPlugins(Container $container): array
    {
        return [
            new MerchantProductCartPreCheckPlugin(),
        ];
    }
}
Verification

Make sure that you can’t add an item with merchantReference and sku that do not belong to the same MerchantProduct(see spy_merchant_product_abstract).

src/Pyz/Yves/CartPage/CartPageDependencyProvider.php

<?php

namespace Pyz\Yves\CartPage;

use SprykerShop\Yves\CartPage\CartPageDependencyProvider as SprykerCartPageDependencyProvider;
use SprykerShop\Yves\MerchantProductWidget\Plugin\CartPage\MerchantProductPreAddToCartPlugin;

class CartPageDependencyProvider extends SprykerCartPageDependencyProvider
{
    /**
     * @return array<\SprykerShop\Yves\CartPageExtension\Dependency\Plugin\PreAddToCartPluginInterface>
     */
    protected function getPreAddToCartPlugins(): array
    {
        return [
            new MerchantProductPreAddToCartPlugin(),
        ];
    }
}
Verification

Make sure that when you add a merchant product to cart, it has merchantReference set. (Can be checked in the spy_quote table).