What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello, we are using the product bundle feature in spryker and we wonder why the items get splitted o

UPWG9AYH2
UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

Hello,
we are using the product bundle feature in spryker and we wonder why the items get splitted on checkout even if they have the same sku just with increased quantity … for that we investigated the quote operation and there is a function in ProductBundleCartExpander

createBundledItemsTransferCollection

which iterates over the bundle items and separate each item to a single item with each quantity = 1 … since we need on order export (from sales object) the “grouped” view of the items …
Why does spryker split up the items by default and set the quantity to 1 for each here?

Best

Comments

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 🧑🏻‍🚀 - Cadet
    edited May 2021

    If you buy 3 boxes of shoes and you want to return just one or deliver them separately it makes your life much easier if the items are split

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited May 2021

    @valerii.trots the isSplittable property is already set to false … doesn’t seem to apply for product bundle items since the mentioned method does not check for it.

    @UKHD8KTMF yes, you are right but it depends on use case … we dont have this use case since our bundle is always threated as a complete unit, parts of it cant be removed.

    However, the thing is, i dont want to make unnecessary work … so for cart its grouped … on sales order it gets separated and for exporting it to external systems we have to write logic, that groups it again … can this be avoided with less effort?

    Best

  • Stanislav Matveyev
    Stanislav Matveyev Tech Lead @ Spryker Sprykee Posts: 211 🧑🏻‍🚀 - Cadet

    try to disable CartChangeTransferQuantityNormalizerPlugin in \Pyz\Zed\Cart\CartDependencyProvider

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    The CartChangeTransferQuantityNormalizerPlugin seems not to be executed at this point …

    The problem is the following code

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    which turns this (quantity = 1 and quantity = 2)

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    into this (3 items with quantity = 1)

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    I would expect two itemtransfers with same as for productforbundletransfers here with the equivalent quantity and no split! But the code does not seem to consider this

  • Stanislav Matveyev
    Stanislav Matveyev Tech Lead @ Spryker Sprykee Posts: 211 🧑🏻‍🚀 - Cadet

    it's a part of \Spryker\Zed\ProductBundle\Communication\Plugin\Cart\ExpandBundleItemsPlugin which is needed, but to achive your goal looks like you need to override \Spryker\Zed\ProductBundle\Business\ProductBundle\Cart\ProductBundleCartExpander on Pyz level

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited May 2021

    If its part of the productbundle and needed to behave like it is, i think we have less headache to not override this code and better re-bundle it later when reading it from the sales table again. Otherwise i fear we may encounter other side effects with things that working well now^^ … i was just curious to know why especially the product bundle items get split up to single items with quantity 1 instead of writing it “as it is” to the quote (and in the end into the sales table). I guess it has something to to with the “rebalancing” of the product bundle sum, where the productbundle price gets distributed over all containing product bundle items.
    Thanks and best regards

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited May 2021

    Seems that bundle items assumed as always splittable … see ItemQuantityValidator

    public function isItemQuantitySplittable(ItemTransfer $itemTransfer): bool
    {

    if ($this->isBundledItem($itemTransfer)) {
    return true;
    }

    }
    protected function isBundledItem(ItemTransfer $itemTransfer)
    {
    if (!method_exists($itemTransfer, ‘getBundleItemIdentifier’)) {
    return false;
    }

    if ($itemTransfer->getRelatedBundleItemIdentifier() || $itemTransfer->getBundleItemIdentifier()) {
        return true;
    }
    
    return false;
    

    }

    $itemTransfer->getRelatedBundleItemIdentifier() is true here since its an item of a bundle
    So technical thats the reason why the items also get split on order save, but from business side, i dont understand the reason why its more or less “hard coded” or assumed that a product bundle item MUST be always splittable …

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    @jeremy.fourna from PO perspective, is there a reason why product bundles are always splittable? Or is it just something that needs to be fixed in core?

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited May 2021

    Or at least fixed for our use case on project level with no or less impact ^^

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice
  • Jeremy Fourna
    Jeremy Fourna Lead Product Manager Posts: 130 🧑🏻‍🚀 - Cadet

    Because product bundles are bundles of existing products that could be shipped separately. This behavior is there since forever 🤷

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    Okay, i also think, that product bundles were never considered using together with merchant related prices, correct?
    We encounter a strange behaviour … when adding a product bundle to cart, the product bundle price (concrete product price) is necessary … but also a default price for each bundled product must be there, even if the price of the bundled product is not considered for the price calculation (price is distributed simply by dividing the product bundle price by bundled items).
    We assume that the merchant price is never considered here, because a filter does not set any merchant price related infos, see ProductBundleCartExpander

    protected function createStoreSpecificPriceProductFilterTransfer(string $sku, QuoteTransfer $quoteTransfer): PriceProductFilterTransfer
        {
            return (new PriceProductFilterTransfer())
                ->setSku($sku)
                ->setCurrencyIsoCode($quoteTransfer->getCurrency()->getCode())
                ->setPriceMode($quoteTransfer->getPriceMode())
                ->setStoreName($quoteTransfer->getStore()->getName());
        }
    

    So here, there will be always the default price, since the facade returns the price dimension default when no price dimension info was given. Therefore, a merchant related price is never considered. On the other side, it could be that this is anyway irrelevant, its just that the normal calulcation stack gets any number to work … just if there is no default price dimension, we get trouble since somewhere is a check to have a valid unit price