Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@develth
Last active March 5, 2021 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save develth/c0fb0d1a9f23beb231e767b7705e0c7d to your computer and use it in GitHub Desktop.
Save develth/c0fb0d1a9f23beb231e767b7705e0c7d to your computer and use it in GitHub Desktop.
shopware6 variant select
  1. Add files
  2. Clear Cache
  3. Build Storefront
  4. Enjoy
{# extend buy-widget-form #}
{% sw_extends '@Storefront/storefront/page/product-detail/buy-widget-form.html.twig' %}
{% block page_product_detail_buy_quantity_container %}
<div class="col-12 col-sm-4 d-flex align-items-end">
{% block page_product_detail_buy_quantity %}
<div class="form-group">
<label for="lineItems[{{ product.id }}][quantity]">{{ 'detail.orderItemQuantity'|trans|sw_sanitize }}</label>
<select name="lineItems[{{ product.id }}][quantity]"
class="custom-select product-detail-quantity-select">
{% for quantity in range(product.minPurchase, product.calculatedMaxPurchase, product.purchaseSteps) %}
<option value="{{ quantity }}">
{{ quantity }}{% if product.packUnit %} {{ product.packUnit }}{% endif %}
</option>
{% endfor %}
</select>
</div>
{% endblock %}
</div>
{% endblock %}
// Add Plugin in /custom/plugins/THEMEPLUGIN/src/Resources/app/storefront/src/main.js
import VariantSwitchPlugin from './variant-switch/variant-switch.plugin';
// if not set yet: const PluginManager = window.PluginManager;
PluginManager.override('VariantSwitch', VariantSwitchPlugin, '[data-variant-switch]');
// create file in /custom/plugins/THEMEPLUGIN/src/Resources/app/storefront/src/variant-switch
import VariantSwitchBasePlugin from 'src/plugin/variant-switch/variant-switch.plugin';
import Iterator from 'src/helper/iterator.helper';
export default class VariantSwitchPlugin extends VariantSwitchBasePlugin {
/**
* returns the current selected
* variant options from the form
*
* @private
*/
_getFormValue() {
const serialized = {};
Iterator.iterate(this._radioFields, field => {
if (VariantSwitchPlugin._isFieldSerializable(field)) {
if (field.selected) {
serialized[field.parentNode.name] = field.value;
}
}
});
return serialized;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment