Install the Cart + Marketplace Product Offer Glue API

Edit on GitHub

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

Install feature core

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

Prerequisites

Install the required features:

NAME VERSION INSTALLATION GUIDE
Cart API 202307.0 Install the Cart Glue API
Marketplace Product Offer API 202307.0 Install the Marketplace Product Offer Glue API
Marketplace Inventory Management 202307.0 Install the Marketplace Inventory Management feature

1) Set up behavior

Enable the following behaviors by registering the plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
MerchantProductOfferCartItemMapperPlugin Maps the merchant product offer reference and merchant reference, coming from the Glue add to cart request, to persistent cart-specific transfer. Spryker\Zed\MerchantProductOffersRestApi\Communication\Plugin\CartsRestApi
MerchantProductOfferCartItemExpanderPlugin Expands the merchant product offer information with a merchant reference. Spryker\Glue\MerchantProductOffersRestApi\Plugin\CartsRestApi
MerchantProductOfferRestCartItemsAttributesMapperPlugin Maps merchant product offer reference and merchant reference to items attributes. Spryker\Glue\MerchantProductOffersRestApi\Plugin\CartsRestApi

src/Pyz/Glue/CartsRestApi/CartsRestApiDependencyProvider.php

<?php

namespace Pyz\Glue\CartsRestApi;

use Spryker\Glue\CartsRestApi\CartsRestApiDependencyProvider as SprykerCartsRestApiDependencyProvider;
use Spryker\Glue\MerchantProductOffersRestApi\Plugin\CartsRestApi\MerchantProductOfferCartItemExpanderPlugin;
use Spryker\Glue\MerchantProductOffersRestApi\Plugin\CartsRestApi\MerchantProductOfferRestCartItemsAttributesMapperPlugin;

class CartsRestApiDependencyProvider extends SprykerCartsRestApiDependencyProvider
{
    /**
     * @return array<\Spryker\Glue\CartsRestApiExtension\Dependency\Plugin\RestCartItemsAttributesMapperPluginInterface>
     */
    protected function getRestCartItemsAttributesMapperPlugins(): array
    {
        return [
            new MerchantProductOfferRestCartItemsAttributesMapperPlugin(),
        ];
    }

    /**
     * @return array<\Spryker\Glue\CartsRestApiExtension\Dependency\Plugin\CartItemExpanderPluginInterface>
     */
    protected function getCartItemExpanderPlugins(): array
    {
        return [
            new MerchantProductOfferCartItemExpanderPlugin(),
        ];
    }
}

src/Pyz/Zed/CartsRestApi/CartsRestApiDependencyProvider.php

<?php

namespace Pyz\Zed\CartsRestApi;

use Spryker\Zed\CartsRestApi\CartsRestApiDependencyProvider as SprykerCartsRestApiDependencyProvider;
use Spryker\Zed\MerchantProductOffersRestApi\Communication\Plugin\CartsRestApi\MerchantProductOfferCartItemMapperPlugin;

class CartsRestApiDependencyProvider extends SprykerCartsRestApiDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CartsRestApiExtension\Dependency\Plugin\CartItemMapperPluginInterface>
     */
    protected function getCartItemMapperPlugins(): array
    {
        return [
            new MerchantProductOfferCartItemMapperPlugin(),
        ];
    }
}
Verification

Make sure that MerchantProductOfferCartItemExpanderPlugin and MerchantProductOfferCartItemMapperPlugin are set up by sending the request POST https://glue.mysprykershop.com/carts/{{cartUuid}}/items with the following body and make sure the product has been added to the cart with the offer:

{
    "data": {
        "type": "items",
        "attributes": {
            "sku": "091_25873091",
            "quantity": "1",
            "productOfferReference": "offer3"
        }
    }
}

Make sure that MerchantProductOfferRestCartItemsAttributesMapperPlugin is set up by sending the request GET https://glue.mysprykershop.com/carts/{{cartUuid}}?include=items to the cart that has an item with a product offer. You should be able to see productOfferReference and merchantReference attributes among the attributes of the items resource.