Customizing the Feed

The app provides numerous events to customize the data and the data feed itself according to specific needs. These events can be "listened to" in a custom app, and the data can be adjusted accordingly.

Eventliste

InstaShoppingProductsCriteriaEvent

This event gives you the opportunity to modify the query for retrieving data through the repository/database. For example, you can implement additional associations or filters.

class InstaShoppingProductsCriteriaEvent extends Event
{
    /** @var Criteria */
    protected $criteria;

    /** @var SalesChannelContext */
    protected $salesChannelContext;

    /**
     * @param Criteria $criteria
     * @param SalesChannelContext $salesChannelContext
     */
    public function __construct(
        Criteria $criteria,
        SalesChannelContext $salesChannelContext
    )
    {
        $this->criteria = $criteria;
        $this->salesChannelContext = $salesChannelContext;
    }

    /**
     * @return Criteria
     */
    public function getCriteria(): Criteria
    {
        return $this->criteria;
    }

    /**
     * @return SalesChannelContext
     */
    public function getSalesChannelContext(): SalesChannelContext
    {
        return $this->salesChannelContext;
    }
}

InstaShoppingProductsLineItemBeforeEvent

The event is triggered after the data array for a product has been created. This provides you with the opportunity to influence the data for each individual row in the CSV file.

class InstaShoppingProductsLineItemBeforeEvent extends Event
{
    /** @var SalesChannelProductEntity */
    protected $product;

    /** @var LineItemStruct */
    protected $lineItem;

    /** @var array */
    protected $propertyData;

    /** @var SettingsStruct */
    protected $settings;

    /**
     * @param SalesChannelProductEntity $product
     * @param array $data
     * @param array $propertyData
     * @param SettingsStruct $settings
     */
    public function __construct(
        SalesChannelProductEntity $product,
        LineItemStruct $lineItem,
        array $propertyData,
        SettingsStruct $settings
    )
    {
        $this->product = $product;
        $this->lineItem = $lineItem;
        $this->propertyData = $propertyData;
        $this->settings = $settings;
    }

    /**
     * @return SalesChannelProductEntity
     */
    public function getProduct(): SalesChannelProductEntity
    {
        return $this->product;
    }

    /**
     * @return LineItemStruct
     */
    public function getLineItem(): LineItemStruct
    {
        return $this->lineItem;
    }

    /**
     * @param LineItemStruct $lineItem
     */
    public function setLineItem(LineItemStruct $lineItem): void
    {
        $this->lineItem = $lineItem;
    }

    /**
     * @return array
     */
    public function getPropertyData(): array
    {
        return $this->propertyData;
    }

    /**
     * @param array $propertyData
     */
    public function setPropertyData(array $propertyData): void
    {
        $this->propertyData = $propertyData;
    }

    /**
     * @return SettingsStruct
     */
    public function getSettings(): SettingsStruct
    {
        return $this->settings;
    }
}

InstaShoppingProductsLineItemsEvent

The event is triggered after the complete data array has been constructed to fill the CSV file. This provides you with the opportunity to modify existing data entirely or use it as a basis for further feeds.

class InstaShoppingProductsLineItemsEvent extends Event
{
    /** @var array */
    protected $lineItems;

    /** @var int */
    protected $variantsCount;

    /**
     * @param array $lineItems
     * @param int $variantsCount
     */
    public function __construct(
        array $lineItems,
        int $variantsCount
    )
    {
        $this->lineItems = $lineItems;
        $this->variantsCount = $variantsCount;
    }

    /**
     * @return array
     */
    public function getLineItems(): array
    {
        return $this->lineItems;
    }

    /**
     * @param array $lineItems
     */
    public function setLineItems(array $lineItems): void
    {
        $this->lineItems = $lineItems;
    }

    /**
     * @return int
     */
    public function getVariantsCount(): int
    {
        return $this->variantsCount;
    }

    /**
     * @param int $variantsCount
     */
    public function setVariantsCount(int $variantsCount): void
    {
        $this->variantsCount = $variantsCount;
    }
}

InstaShoppingProductsProcessingBeforeEvent

This event provides access to the product result (SalesChannelRepositoryIterator::fetch()). You have the opportunity to adjust data or create an additional data feed with the determined products, allowing you to potentially integrate other services.

class InstaShoppingProductsProcessingBeforeEvent extends Event
{
    /** @var SalesChannelRepositoryIterator */
    protected $iterator;

    /** @var EntitySearchResult */
    protected $productResult;

    /** @var SalesChannelDomainEntity */
    protected $channelDomain;

    /**
     * @param SalesChannelRepositoryIterator $iterator
     * @param EntitySearchResult $productResult
     * @param SalesChannelDomainEntity $channelDomain
     */
    public function __construct(
        SalesChannelRepositoryIterator $iterator,
        EntitySearchResult $productResult,
        SalesChannelDomainEntity $channelDomain
    )
    {
        $this->iterator = $iterator;
        $this->productResult = $productResult;
        $this->channelDomain = $channelDomain;
    }


    /**
     * @return SalesChannelRepositoryIterator
     */
    public function getIterator(): SalesChannelRepositoryIterator
    {
        return $this->iterator;
    }

    /**
     * @return EntitySearchResult
     */
    public function getProductResult(): EntitySearchResult
    {
        return $this->productResult;
    }

    /**
     * @return SalesChannelDomainEntity
     */
    public function getSalesChannelDomain(): SalesChannelDomainEntity
    {
        return $this->channelDomain;
    }
}

InstaShoppingCsvHeaderBeforeEvent

This event can be used to adjust or expand the header fields in the CSV file.

class InstaShoppingCsvHeaderBeforeEvent extends Event
{
    /** @var array */
    protected $header;

    /**
     * @param array $header
     */
    public function __construct(
        array $header
    )
    {
        $this->header = $header;
    }

    /**
     * @return array
     */
    public function getHeader(): array
    {
        return $this->header;
    }

    /**
     * @param array $header
     */
    public function setHeader(array $header): void
    {
        $this->header = $header;
    }
}

InstaShoppingCsvLineItemBeforeEvent

This event can be used to adjust or expand the product data fields in the CSV file.

class InstaShoppingCsvLineItemBeforeEvent extends Event
{
    /** @var array */
    protected $fields;

    /**
     * @param array $fields
     */
    public function __construct(
        array $fields
    )
    {
        $this->fields = $fields;
    }

    /**
     * @return array
     */
    public function getFields(): array
    {
        return $this->fields;
    }

    /**
     * @param array $fields
     */
    public function setFields(array $fields): void
    {
        $this->fields = $fields;
    }
}

LineItemStruct (Field definition)

class LineItemStruct implements \JsonSerializable
{
    //allows json_encode and to decode object via json serializer
    use JsonSerializableTrait;

    //allows access to all protected variables of the object
    use VariablesAccessTrait;

    //allows to assign array data to this object
    use AssignArrayTrait;

    /** @var string */
    protected $orderNumber;

    /** @var string */
    protected $ean;

    /** @var string */
    protected $name;

    /** @var string */
    protected $description;

    /** @var string */
    protected $stock;

    /** @var string */
    protected $condition;

    /** @var string */
    protected $priceRegular;

    /** @var string */
    protected $priceSale;

    /** @var string */
    protected $weight;

    /** @var string */
    protected $url;

    /** @var string */
    protected $mainImage;

    /** @var string */
    protected $brand;

    /** @var string */
    protected $categoryPath;

    /** @var string */
    protected $additionalImages;

    /** @var string */
    protected $itemGroupId;

    /** @var string */
    protected $customLabel0;

    /** @var int */
    protected $inventory;

    /** @var string */
    protected $originCountry;

    /** @var string */
    protected $googleCategory;

    /** @var string */
    protected $size;

    /** @var string */
    protected $color;

    /** @var string */
    protected $gender;

    /** @var string */
    protected $ageGroup;

    /** @var string */
    protected $pattern;

    /** @var string */
    protected $material;

    /**
     * @return string
     */
    public function getOrderNumber(): string
    {
        return $this->orderNumber;
    }

    /**
     * @param string $orderNumber
     */
    public function setOrderNumber(string $orderNumber): void
    {
        $this->orderNumber = $orderNumber;
    }

    /**
     * @return string
     */
    public function getEan(): string
    {
        return $this->ean;
    }

    /**
     * @param ?string $ean
     */
    public function setEan(?string $ean): void
    {
        $this->ean = $ean;
    }

    /**
     * @return string
     */
    public function getName(): ?string
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name): void
    {
        $this->name = $name;
    }

    /**
     * @return string
     */
    public function getDescription(): string
    {
        return $this->description;
    }

    /**
     * @param string $description
     */
    public function setDescription(string $description): void
    {
        $this->description = $description;
    }

    /**
     * @return string
     */
    public function getStock(): string
    {
        return $this->stock;
    }

    /**
     * @param string $stock
     */
    public function setStock(string $stock): void
    {
        $this->stock = $stock;
    }

    /**
     * @return string
     */
    public function getCondition(): string
    {
        return $this->condition;
    }

    /**
     * @param string $condition
     */
    public function setCondition(string $condition): void
    {
        $this->condition = $condition;
    }

    /**
     * @return string
     */
    public function getPriceRegular(): string
    {
        return $this->priceRegular;
    }

    /**
     * @param string $priceRegular
     */
    public function setPriceRegular(string $priceRegular): void
    {
        $this->priceRegular = $priceRegular;
    }

    /**
     * @return string
     */
    public function getPriceSale(): string
    {
        return $this->priceSale;
    }

    /**
     * @param string $priceSale
     */
    public function setPriceSale(string $priceSale): void
    {
        $this->priceSale = $priceSale;
    }

    /**
     * @return string
     */
    public function getWeight(): string
    {
        return $this->weight;
    }

    /**
     * @param string $weight
     */
    public function setWeight(string $weight): void
    {
        $this->weight = $weight;
    }

    /**
     * @return string
     */
    public function getUrl(): string
    {
        return $this->url;
    }

    /**
     * @param string $url
     */
    public function setUrl(string $url): void
    {
        $this->url = $url;
    }

    /**
     * @return string
     */
    public function getMainImage(): string
    {
        return $this->mainImage;
    }

    /**
     * @param string $mainImage
     */
    public function setMainImage(string $mainImage): void
    {
        $this->mainImage = $mainImage;
    }

    /**
     * @return string
     */
    public function getBrand(): string
    {
        return $this->brand;
    }

    /**
     * @param string $brand
     */
    public function setBrand(string $brand): void
    {
        $this->brand = $brand;
    }

    /**
     * @return string
     */
    public function getCategoryPath(): string
    {
        return $this->categoryPath;
    }

    /**
     * @param string $categoryPath
     */
    public function setCategoryPath(string $categoryPath): void
    {
        $this->categoryPath = $categoryPath;
    }

    /**
     * @return string
     */
    public function getAdditionalImages(): string
    {
        return $this->additionalImages;
    }

    /**
     * @param string $additionalImages
     */
    public function setAdditionalImages(string $additionalImages): void
    {
        $this->additionalImages = $additionalImages;
    }

    /**
     * @return string
     */
    public function getItemGroupId(): string
    {
        return $this->itemGroupId;
    }

    /**
     * @param string $itemGroupId
     */
    public function setItemGroupId(string $itemGroupId): void
    {
        $this->itemGroupId = $itemGroupId;
    }

    /**
     * @return string
     */
    public function getCustomLabel0(): string
    {
        return $this->customLabel0;
    }

    /**
     * @param string $customLabel0
     */
    public function setCustomLabel0(string $customLabel0): void
    {
        $this->customLabel0 = $customLabel0;
    }

    /**
     * @return int
     */
    public function getInventory(): int
    {
        return $this->inventory;
    }

    /**
     * @param int $inventory
     */
    public function setInventory(int $inventory): void
    {
        $this->inventory = $inventory;
    }

    /**
     * @return string
     */
    public function getOriginCountry(): string
    {
        return $this->originCountry;
    }

    /**
     * @param string $originCountry
     */
    public function setOriginCountry(string $originCountry): void
    {
        $this->originCountry = $originCountry;
    }

    /**
     * @return string
     */
    public function getGoogleCategory(): string
    {
        return $this->googleCategory;
    }

    /**
     * @param string $googleCategory
     */
    public function setGoogleCategory(string $googleCategory): void
    {
        $this->googleCategory = $googleCategory;
    }

    /**
     * @return string
     */
    public function getSize(): string
    {
        return $this->size;
    }

    /**
     * @param string $size
     */
    public function setSize(string $size): void
    {
        $this->size = $size;
    }

    /**
     * @return string
     */
    public function getColor(): string
    {
        return $this->color;
    }

    /**
     * @param string $color
     */
    public function setColor(string $color): void
    {
        $this->color = $color;
    }

    /**
     * @return string
     */
    public function getGender(): string
    {
        return $this->gender;
    }

    /**
     * @param string $gender
     */
    public function setGender(string $gender): void
    {
        $this->gender = $gender;
    }

    /**
     * @return string
     */
    public function getAgeGroup(): string
    {
        return $this->ageGroup;
    }

    /**
     * @param string $ageGroup
     */
    public function setAgeGroup(string $ageGroup): void
    {
        $this->ageGroup = $ageGroup;
    }

    /**
     * @return string
     */
    public function getPattern(): string
    {
        return $this->pattern;
    }

    /**
     * @param string $pattern
     */
    public function setPattern(string $pattern): void
    {
        $this->pattern = $pattern;
    }

    /**
     * @return string
     */
    public function getMaterial(): string
    {
        return $this->material;
    }

    /**
     * @param string $material
     */
    public function setMaterial(string $material): void
    {
        $this->material = $material;
    }
}

Starter Modify App

To simplify the customization process for you, we provide our BstInstaShoppingModify6 app for free. You can download, install, and customize this app according to your preferences.

BstInstaShoppingModify6: https://shopware.brainstation.de/plugins/sw6/BstInstaShoppingModify6_v1.1.0.zip

Examples

Steer the category name SALE as soon as the product has a special offer price or a strike-through price.

/**
     * @param InstaShoppingProductsLineItemBeforeEvent $event
     */
    public function onLineItemBefore(InstaShoppingProductsLineItemBeforeEvent $event): void
    {
        /** @var ProductEntity $product */
        $product = $event->getProduct();

        /** @var LineItemStruct $lineItem */
        $lineItem = $event->getLineItem();

        /** @var array $propertyData */
        $propertyData = $event->getPropertyData();

        /** @var SettingsStruct $settings */
        $settings = $event->getSettings();

        // Example: Check if product is on sale. In this case export SALE Category for product_type
        if ($product->getPrice()->first()->getListPrice()) {
            $lineItem->setCategoryPath('SALE');
        }

        $event->setLineItem($lineItem);
    }

Insert additional field in the CSV

/**
 * @param InstaShoppingCsvHeaderBeforeEvent $event
 */
public function onCsvHeaderBefore(InstaShoppingCsvHeaderBeforeEvent $event): void
{
    $header = $event->getHeader();
    $header[] = 'Custom Column';
    $event->setHeader($header);
}


/**
 * @param InstaShoppingCsvLineItemBeforeEvent $event
 */
public function onCsvLineItemBefore(InstaShoppingCsvLineItemBeforeEvent $event): void
{
    $lineItemFields = $event->getFields();
    $lineItemFields[] = 'Field value';
    $event->setFields($lineItemFields);
}

Last updated