Glue API: Marketplace Product Offer + Wishlist feature integration

Edit on GitHub

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

Install feature core

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

Prerequisites

To start feature integration, integrate the required features:

NAME VERSION INTEGRATION GUIDE
Marketplace Wishlist 202108.0 Wishlist feature integration
Marketplace Product Offer API 202108.0 Glue API: Marketplace Product Offer feature integration

1) Install the required modules using Composer

Install the required modules:

composer require spryker/merchant-product-offer-wishlist-rest-api:"^1.0.0" --update-with-dependencies
Verification

Make sure that the following modules have been installed:

MODULE EXPECTED DIRECTORY
MerchantProductOfferWishlistRestApi spryker/merchant-product-offer-wishlist-rest-api

2) 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
WishlistItemRequest.productOfferReference property Created src/Generated/Shared/Transfer/WishlistItemRequestTransfer
RestWishlistItemsAttributes.productOfferReference property Created src/Generated/Shared/Transfer/RestWishlistItemsAttributesTransfer
RestWishlistItemsAttributes.merchantReference property Created src/Generated/Shared/Transfer/RestWishlistItemsAttributesTransfer

3) Set up behavior

Activate the following plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
MerchantProductOfferAddItemPreCheckPlugin Returns WishlistPreAddItemCheckResponse.isSuccess=false if no product offers found by the WishlistItem.productOfferReference transfer property. Spryker\Zed\MerchantProductOfferWishlist\Communication\Plugin\Wishlist
ProductOfferRestWishlistItemsAttributesMapperPlugin Populates RestWishlistItemsAttributes.id with the following pattern: {WishlistItem.sku}_{WishlistItemTransfer.productOfferReference}. Spryker\Glue\MerchantProductOfferWishlistRestApi\Plugin\Wishlist
ProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin Checks if requested the wishlist item exists in the wishlist item collection. Spryker\Zed\MerchantProductOfferWishlistRestApi\Communication\Plugin
EmptyProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin Checks if the requested wishlist item exists in the wishlist item collection. Spryker\Zed\MerchantProductOfferWishlistRestApi\Communication\Plugin
MerchantByMerchantReferenceResourceRelationshipPlugin Adds merchants resources as relationship by merchant references in the attributes. Spryker\Glue\MerchantsRestApi\Plugin\GlueApplication
src/Pyz/Glue/GlueApplication/GlueApplicationDependencyProvider.php
<?php

namespace Pyz\Glue\GlueApplication;

use Spryker\Glue\GlueApplication\GlueApplicationDependencyProvider as SprykerGlueApplicationDependencyProvider;
use Spryker\Glue\MerchantsRestApi\Plugin\GlueApplication\MerchantByMerchantReferenceResourceRelationshipPlugin;
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface;
use Spryker\Glue\WishlistsRestApi\WishlistsRestApiConfig;

class GlueApplicationDependencyProvider extends SprykerGlueApplicationDependencyProvider
{
    /**
     * @param \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface $resourceRelationshipCollection
     *
     * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface
     */
    protected function getResourceRelationshipPlugins(
        ResourceRelationshipCollectionInterface $resourceRelationshipCollection
    ): ResourceRelationshipCollectionInterface {
        $resourceRelationshipCollection->addRelationship(
            WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS,
            new MerchantByMerchantReferenceResourceRelationshipPlugin()
        );

        return $resourceRelationshipCollection;
    }
}
src/Pyz/Zed/Wishlist/WishlistDependencyProvider.php
<?php
namespace Pyz\Zed\Wishlist;

use Spryker\Zed\MerchantProductOfferWishlist\Communication\Plugin\Wishlist\MerchantProductOfferAddItemPreCheckPlugin;
use Spryker\Zed\Wishlist\WishlistDependencyProvider as SprykerWishlistDependencyProvider;

class WishlistDependencyProvider extends SprykerWishlistDependencyProvider
{
    /**
     * @return \Spryker\Zed\WishlistExtension\Dependency\Plugin\AddItemPreCheckPluginInterface[]
     */
    protected function getAddItemPreCheckPlugins(): array
    {
        return [
            new MerchantProductOfferAddItemPreCheckPlugin(),
        ];
    }

}
src/Pyz/Glue/WishlistsRestApi/WishlistsRestApiDependencyProvider.php
<?php

namespace Pyz\Glue\WishlistsRestApi;

use Spryker\Glue\MerchantProductOfferWishlistRestApi\Plugin\Wishlist\ProductOfferRestWishlistItemsAttributesMapperPlugin;
use Spryker\Glue\WishlistsRestApi\WishlistsRestApiDependencyProvider as SprykerWishlistsRestApiDependencyProvider;

class WishlistsRestApiDependencyProvider extends SprykerWishlistsRestApiDependencyProvider
{
    /**
     * @return \Spryker\Glue\WishlistsRestApiExtension\Dependency\Plugin\RestWishlistItemsAttributesMapperPluginInterface[]
     */
    protected function getRestWishlistItemsAttributesMapperPlugins(): array
    {
        return [
            new ProductOfferRestWishlistItemsAttributesMapperPlugin(),
        ];
    }
}
src/Pyz/Zed/WishlistsRestApi/WishlistsRestApiDependencyProvider.php
<?php
namespace Pyz\Zed\WishlistsRestApi;

use Spryker\Zed\MerchantProductOfferWishlistRestApi\Communication\Plugin\EmptyProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin;
use Spryker\Zed\MerchantProductOfferWishlistRestApi\Communication\Plugin\ProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin;
use Spryker\Zed\WishlistsRestApi\WishlistsRestApiDependencyProvider as SprykerWishlistsRestApiDependencyProvider;

class WishlistsRestApiDependencyProvider extends SprykerWishlistsRestApiDependencyProvider
{
    /**
     * @return \Spryker\Zed\WishlistsRestApiExtension\Dependency\Plugin\RestWishlistItemsAttributesDeleteStrategyPluginInterface[]
     */
    protected function getRestWishlistItemsAttributesDeleteStrategyPlugins(): array
    {
        return [
            new ProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin(),
            new EmptyProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin(),
        ];
    }
}
Verification

Make sure that ProductOfferRestWishlistItemsAttributesMapperPlugin is set up by sending the request GET http://glue.mysprykershop.com/wishlists/{{wishlistId}}?include=wishlist-items. You should get attributes in the response.

Make sure that MerchantProductOfferAddItemPreCheckPlugin is set up by sending the request POST http://glue.mysprykershop.com/wishlists/{{wishlistId}}/wishlist-items. You should have the wishlist item added only when the product has the specified offer reference.

Make sure that ProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin and EmptyProductOfferRestWishlistItemsAttributesDeleteStrategyPlugin are set up by sending the request DELETE http://glue.mysprykershop.com/wishlists/{{wishlistId}}/wishlist-items/{{wishlistItemId}}. You should get the product offer wishlist item deleted.