How do I extend pipelines?
The payload data can be altered using the extend() method. This is typically done from within a Service Provider:
- If the code is unique to a particular store it could be placed in the
boot()method of theAppServiceProvider. - If it is to be included as part of a module, then it can be added to the setup method of the module's Service Provider.
For example, if a module needs to add an option to items to flag them as requiring gift wrap, the CartItemBuilder pipeline class should be extended in the module's ServiceProvider as shown below:
<?php
namespace Aerocargo\Acme;
use Aero\Cart\CartItemOption;
use Aero\Common\Providers\ModuleServiceProvider;
use Aero\Store\Pipelines\CartItemBuilder;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
CartItemBuilder::extend(function ($item) {
if (request()->has('gift_wrap')) {
$option = CartItemOption::create('Gift wrap');
$item->addOption($option);
}
});
}
}