Git Product home page Git Product logo

Comments (3)

lchrusciel avatar lchrusciel commented on June 3, 2024 1

After short discussion with @GSadee & @NoResponseMate we are aiming to fix it in 2.0

from sylius.

gitrequests avatar gitrequests commented on June 3, 2024

If you're looking for a real world example of this problem, I can provide that.

Add an “Add to Cart” button to the card content. To do this, you can only fix one file.
File '@SyliusShop/Product/Box/_content.html.twig'

{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

<div class="ui fluid card" {{ sylius_test_html_attribute('product') }}>
    <a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="blurring dimmable image">
        <div class="ui dimmer">
            <div class="content">
                <div class="center">
                    <div class="ui inverted button">{{ 'sylius.ui.view_more'|trans }}</div>
                </div>
            </div>
        </div>
        {% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product} %}
    </a>
    <div class="content" {{ sylius_test_html_attribute('product-content') }}>
        <a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="header sylius-product-name" {{ sylius_test_html_attribute('product-name', product.name) }}>{{ product.name }}</a>

        {% if not product.enabledVariants.empty() %}
            {% set variant = product|sylius_resolve_variant %}
            {% set price = money.calculatePrice(variant) %}
            {% set originalPrice = money.calculateOriginalPrice(variant) %}
            {% set appliedPromotions = variant.getAppliedPromotionsForChannel(sylius.channel) %}

            {% include '@SyliusShop/Product/Show/_catalogPromotionLabels.html.twig' with {'appliedPromotions': appliedPromotions, 'withDescription': false} %}

            {# RENDER “ADD TO CART” BUTTON #}
            {{ render(url('sylius_shop_partial_cart_add_item', {'template': '@SyliusShop/Product/Show/_addToCart.html.twig', 'productId': product.id})) }}

            {% if variant|sylius_has_discount({'channel': sylius.channel}) %}
            <div class="sylius-product-original-price" {{ sylius_test_html_attribute('product-original-price') }}><del>{{ originalPrice }}</del></div>
            {% endif %}
            <div class="sylius-product-price" {{ sylius_test_html_attribute('product-price') }}>{{ price }}</div>
        {% endif %}
    </div>
</div>

Your taxon page now displays an "Add to Cart" button for all products (just needs a styling fix)
Screenshot from 2024-01-23 20-01-51


And the product page (where the "Variant selection method" is not “Variant choice”) works and the latest product widget looks like this.
Screenshot from 2024-01-23 20-05-27


But if you open the product page where "Variant Selection Method" is "Variant choice", an error will appear.
Screenshot from 2024-01-23 18-46-57

from sylius.

lchrusciel avatar lchrusciel commented on June 3, 2024

The root of the problem is that we are using two different form types based on the entity config behind one key in the form builder. Now, if both are used, Twig cache is misconfigured, and we have a cache hit for the appropriate key (_sylius_add_to_cart_cartItem_variant_entry_widget) even though the block hierarchy is different.

We could change keys in our cart item type extension as follows:
https://gist.github.com/lchrusciel/d247fae6fa661867cbd0bbb8948f1cc1#file-cartitemtypeextension-php-L28-L41
instead of

$type =
Product::VARIANT_SELECTION_CHOICE === $options['product']->getVariantSelectionMethod()
? ProductVariantChoiceType::class
: ProductVariantMatchType::class
;
$builder->add('variant', $type, [
'product' => $options['product'],
]);

My main concern is that it is kind of BC-Break and templates would need to be adjusted in two places (_variants.html.twig and _options.html.twig).

The best option would be to fix it in Symfony. Mostly, we could propose that if the cached value is false, we still iterate over the hierarchy. Fixed code could look like this: TwigRendererEngine.php

I hope that it helps!

from sylius.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.