Prices feature integration

Edit on GitHub
Attention!
The following feature integration guide expects the basic feature to be in place.The current feature integration guide only adds the **Volume Prices** functionality.

Install Feature Core

Prerequisites

To start feature integration, overview and install the necessary features:

Name Version
Spryker Core 201903.0
Prices 201903.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require spryker-feature/prices: "^201903.0" --update-with-dependencies
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`PriceProductVolume``vendor/spryker/price-product-volume`
`PriceProductDataImport``vendor/spryker/price-product-data-import`

2) Set up the Transfer Objects

Run the following commands to generate transfer changes:

console transfer:generate
Verification
Make sure that the following changes have been applied to transfer objects:
TransferTypeEventPath
`PriceProduct.volumeQuantity`propertycreated`src/Generated/Shared/Transfer/PriceProductTransfer`
`PriceProductVolume`classcreated`src/Generated/Shared/Transfer/PriceProductVolumeTransfer`
`PriceProductVolumeCollection`classcreated`src/Generated/Shared/Transfer/PriceProductVolumeCollectionTransfer`

3) Import Data

Import Volume Prices

Note
The following imported entities will be used as *productvol* in Spryker OS.

Prepare your data according to your requirements using our demo data:

src/data/import/product_price.csv
193,,DEFAULT,DE,EUR,16195,17994,"[{""quantity"":5,""net_price"":150,""gross_price"":165}, {""quantity"":10,""net_price"":145,""gross_price"":158}, {""quantity"":20,""net_price"":140,""gross_price"":152}]"
195,,DEFAULT,DE,CHF,40848,45387,"[{""quantity"":3,""net_price"":350,""gross_price"":385}, {""quantity"":8,""net_price"":340,""gross_price"":375}]"
194,,DEFAULT,AT,EUR,20780,23089,"[{""quantity"":5,""net_price"":265,""gross_price"":295}, {""quantity"":10,""net_price"":275,""gross_price"":310}, {""quantity"":20,""net_price"":285,""gross_price"":320}]"

Column REQUIRED Data Type Data Example Data Explanation
abstract_sku optional string 193 Either abstract_sku or concrete_sku should exist to attach the given prices to the correct product.
concrete_sku optional string 117_29890338 Either abstract_sku or concrete_sku should exist to attach the given prices to the correct product.
price_type mandatory string DEFAULT None
store mandatory string DE Store in which the specific product has that specific price.
currency mandatory string EUR Currency in which the specific product has that specific price.
value_net mandatory integer 10200 Net (after tax is applied) price in cents.
value_gross mandatory integer 12000 Gross (before tax is applied) price in cents.
price_data.volume_prices optional json string “[{”“quantity””:5,”“net_price””:150,”“gross_price””:165}]” JSON description of the prices when the quantity is changed (volume-based pricing). In the given example, the product bought, when it has a quantity of less than 5, uses the normal price, but it uses this Volume Price when the quantity is greater than 5.

Register the following plugin to enable data import:

Plugin Specification Prerequisites Namespace
PriceProductDataImportPlugin Imports demo product price data into the database. None Spryker\Zed\PriceProductDataImport\Communication\Plugin
src/Pyz/Zed/DataImport/DataImportDependencyProvider.php
 <?php

namespace Pyz\Zed\DataImport;

use Spryker\Zed\DataImport\DataImportDependencyProvider as SprykerDataImportDependencyProvider;
use Spryker\Zed\PriceProductDataImport\Communication\Plugin\PriceProductDataImportPlugin;

class DataImportDependencyProvider extends SprykerDataImportDependencyProvider
{
	protected function getDataImporterPlugins(): array
	{
		return [
			new PriceProductDataImportPlugin(),
		];
	}
}

Run the following console command to import data:

console data:import price-product 
Verification
Make sure that the configured data is added to the `spy_product_price` table in the database.

4) Set up Behavior

Enable the following behaviors by registering the plugins:

Plugin Specification Prerequisites Namespace
PriceProductVolumeExtractorPlugin Provides the ability to extract Volume Prices from an array of PriceProductTransfers for abstract or concrete products to show them to the customer on the Frontend side during the buying process. None Spryker\Client\PriceProductVolume\Plugin\PriceProductStorageExtension
PriceProductVolumeExtractorPlugin Provides the ability to extract Volume Prices from an array of PriceProductTransfers for abstract or concrete products to validate prices when adding items to cart or to validate prices on the backend side. None Spryker\Zed\PriceProductVolume\Communication\Plugin\PriceProductExtension
PriceProductVolumeFilterPlugin Provides the ability to decide based on the selected product quantity, which PriceProduct should be chosen based on the Volume Prices set. None Spryker\Service\PriceProductVolume\Plugin\PriceProductExtension
src/Pyz/Zed/PriceProduct/PriceProductDependencyProvider.php
<?php

namespace Pyz\Zed\PriceProduct;

use Spryker\Zed\PriceProduct\PriceProductDependencyProvider as SprykerPriceProductDependencyProvider;
use Spryker\Zed\PriceProductVolume\Communication\Plugin\PriceProductExtension\PriceProductVolumeExtractorPlugin;

class PriceProductDependencyProvider extends SprykerPriceProductDependencyProvider
{
	/**
	* @return \Spryker\Zed\PriceProductExtension\Dependency\Plugin\PriceProductReaderPricesExtractorPluginInterface[]
	*/
	protected function getPriceProductPricesExtractorPlugins(): array
	{
		return [
			new PriceProductVolumeExtractorPlugin(),
		];
	}
}

src/Pyz/Client/PriceProductStorage/PriceProductStorageDependencyProvider.php
<?php

namespace Pyz\Client\PriceProductStorage;

use Spryker\Client\PriceProductStorage\PriceProductStorageDependencyProvider as SprykerPriceProductStorageDependencyProvider;
use Spryker\Client\PriceProductVolume\Plugin\PriceProductStorageExtension\PriceProductVolumeExtractorPlugin;

class PriceProductStorageDependencyProvider extends SprykerPriceProductStorageDependencyProvider
{
   /**
   * @return \Spryker\Client\PriceProductStorageExtension\Dependency\Plugin\PriceProductStoragePricesExtractorPluginInterface[]
   */
   protected function getPriceProductPricesExtractorPlugins(): array
   {
   	return [
   		new PriceProductVolumeExtractorPlugin(),
   	];
   }
}


src/Pyz/Service/PriceProduct/PriceProductDependencyProvider.php
<?php

namespace Pyz\Service\PriceProduct;

use Spryker\Service\PriceProduct\PriceProductDependencyProvider as SprykerPriceProductDependencyProvider;
use Spryker\Service\PriceProductVolume\Plugin\PriceProductExtension\PriceProductVolumeFilterPlugin;

class PriceProductDependencyProvider extends SprykerPriceProductDependencyProvider
{
	/**
	* {@inheritdoc}
	*
	* @return \Spryker\Service\PriceProductExtension\Dependency\Plugin\PriceProductFilterPluginInterface[]
	*/
	protected function getPriceProductDecisionPlugins(): array
	{
		return array_merge([
			new PriceProductVolumeFilterPlugin(),
		], parent::getPriceProductDecisionPlugins());
	}
}

Verification
Go to the Product Detail page of the product with the Volume Prices set, update the quantity to meet any of Volume Prices boundaries and check the price. Then, add the product to the cart and if the item price in cart remains the same as it was on the Product Detail page, the plugins are installed.

Install feature frontend

Prerequisites

Please overview and install the necessary features before beginning the integration step.

Name Version
Spryker Core E-commerce 201903.0
Prices 201903.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require spryker-feature/prices: "^201903.0" --update-with-dependencies
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`PriceProductVolumeWidget``vendor/spryker-shop/price-product-volume-widget`

2) Add Translations

Append glossary according to your configuration:

src/data/import/glossary.csv
page.detail.volume_price.quantity,Quantity,en_US
page.detail.volume_price.quantity,Anzahl,de_DE
page.detail.volume_price.price,Price,en_US
page.detail.volume_price.price,Preis,de_DE

Run the following console command to import data:

console data:import glossary
Verification
Make sure that in the database the configured data are added to the `spy_glossary` table.

3) Set up Widgets

Enable Global Widgets:

Widget Description Namespace
ProductPriceVolumeWidget Shows a table of Volume Prices for a product that contains the following columns: quantity and price for that quantity threshold. SprykerShop\Yves\PriceProductVolumeWidget\Widget
src/Pyz/Yves/ShopApplication/ShopApplicationDependencyProvider.php
<?php

namespace Pyz\Yves\ShopApplication;

use SprykerShop\Yves\ShopApplication\ShopApplicationDependencyProvider as SprykerShopApplicationDependencyProvider;
use SprykerShop\Yves\PriceProductVolumeWidget\Widget\ProductPriceVolumeWidget;

class ShopApplicationDependencyProvider extends SprykerShopApplicationDependencyProvider
{
	/**
	* @return string[]
	*/
	protected function getGlobalWidgets(): array
	{
		return [
			ProductPriceVolumeWidget::class,
		];
	}
}

Verification
Make sure that the following widgets were registered:
ModuleTest
`ProductPriceVolumeWidget`Go to the Product Detail page for a product with the Volume Prices set, and view the table in the detail area that contains the Volume Prices data.