Magento 2

Stop Magento 2 from Redirecting on Ajax Add to Cart

Useful for debugging the ajax request. Comment out the location.reload() in the ajaxSubmit function in module-catalog/view/frontend/web/js/catalog-add-to-cart.js

/** @inheritdoc */
complete: function (res) {
    if (res.state() === 'rejected') {
        // location.reload();

Multiselects as Type Text; Magento 2.3.2 indexing woes

Creating a multiselect in Magento when an attribute has many, many values gets truncated when it’s indexed into the catalog_product_flat table. This is because the catalog_product_flat table’s column is made specifically as a type varchar as length 255 for multiselects.

A fix is to create a plugin for the \Magento\Eav\Model\Entity\Attribute\Source\Table class;


<type name="Magento\Eav\Model\Entity\Attribute\Source\Table">
    <plugin name="module_eav_entity_attribute_source_table" type="Namespace\Module\Plugin\Eav\Model\Entity\Attribute\Source\Table" sortOrder="10"/>

And the PHP class…

namespace Namespace\Module\Plugin\Eav\Model\Entity\Attribute\Source;

class Table
     * For some reason, Magento indexes text types which are multiselects and type text as varchar 255.
     * This keeps the creation of text index columns so they stay as text type
     * @param \Magento\Eav\Model\Entity\Attribute\Source\Table $subject
     * @param array $result
     * @return array
    public function afterGetFlatColumns(
    ) {
        $attributeCode = $subject->getAttribute()->getAttributeCode();
        $isMulti = $subject->getAttribute()->getFrontend()->getInputType() == 'multiselect';

        if($isMulti && $subject->getAttribute()->getBackendType() == \Magento\Framework\DB\Ddl\Table::TYPE_TEXT) {
            $result[$attributeCode]['length'] = null;

        return $result;

This doesn’t appear to be intended, maybe Magento don’t recommend creating multiselects as type text anymore, but that’s no good for all use cases. Ho-hum.