[SOLVED] Magento 2 Error: A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later.

Sometimes debugging on Magento can be annoying, specially if something just arises out of the blue, not while you are actually writing a code. This is something that occurs on Magento admin panel. As of now, it can be one out of 3 reasons, let us discuss them: 1. Admin Password Try to change admin password, log out and log in again. This should fix it. ...

March 15, 2018 · 1 min · Harshvardhan Malpani

How to tweak Magento 2 for two letter search in fulltext mode

The problem: Magento 2 wont return any search results if the search token is 2 letters in length. Solution: Alter MySQL conf file. Edit my.cnf file on your server In CentOS, use command nano /etc/my.cnf and add the following lines: ft_min_word_len=2 innodb_ft_min_token_size=2 Save using CTRL+x and then restart mysqld service. Now we need to regenerate the index in order to get updated search results. Use the following SQL commands to regenerate: ...

March 2, 2018 · 1 min · Harshvardhan Malpani

Magento 2 : How to fix tablespace for table exists | base table or view already exists

Fixing General error: 1813 Tablespace for table xx Please DISCARD the tablespace before IMPORT and SQLSTATE[42S01]: Base table or view already exists\ Recently I encountered this error while upgrading an extension on Magento 2.2.2 The error was SQLSTATE[HY000]: General error: 1813 Tablespace for table '`jack_db1`.`jill_table`' exists. Please DISCARD the tablespace before IMPORT., query was: CREATE TABLE IF NOT EXISTS `jill_table` When I tried to fix the above error, I received: ...

February 26, 2018 · 2 min · Harshvardhan Malpani

Remove sku column from Magento 2 invoice and pdf

Edit the file /vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php Inside function draw(), remove/comment following code: // draw SKU $lines[0][] = [ 'text' => $this->string->split($this->getSku($item), 17), 'feed' => 290, 'align' => 'right', ]; To remove the SKU header in table header, edit the file /vendor/magento/module-sales/Model/Order/Pdf/Invoice.php 95 //$lines[0][] = ['text' => __('SKU'), 'feed' => 290, 'align' => 'right']; and copy the file vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to app/design/your/theme/Magento_Sales/templates/email/items/order/default.phtml and remove the code <p class="sku"><?= /* @escapeNotVerified */ __('SKU') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>

February 21, 2018 · 1 min · Harshvardhan Malpani

Magento 2 how to show configurable options stock availability on product page

addtocart.phtml <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** @var $block \Magento\Catalog\Block\Product\View */ ?> <?php $_product = $block->getProduct(); ?> <?php $buttonTitle = __('Add to Cart'); ?> <?php if ($_product->isSaleable()): ?> <div class="box-tocart"> <div class="fieldset"> <?php if ($block->shouldRenderQuantity()): $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');?> <div class="field qty"> <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label> <div class="control"> <?php if($_product->getTypeId()=="simple") { ?> <select class="input-text qty" name="qty" id="qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"> <?php $availableQty= $StockState->getStockQty($_product->getId(), $_product->getStore()->getWebsiteId()); for($repli=1;$repli<=$availableQty;$repli++) echo "<option value='$repli'>$repli</option>"; ?> </select> <?php } else { $usedProducts = $_product->getTypeInstance()->getUsedProducts($_product); $productStockd=$objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface'); $finalconfigqty=[]; foreach ($usedProducts as $child) {$childid=$child->getId(); $productStockObj = $productStockd->getStockItem($childid); $availableQty= round($productStockObj->getData('qty')); $finalconfigqty['c'.$childid]=$availableQty; } echo '<script> var fichoo='. json_encode($finalconfigqty). '</script>'; echo '<select class="input-text qty fichoo" name="qty" id="qty"><option value=1>1</option></select>'; ?> <!--input type="number" name="qty" id="qty" value="<?= $block->getProductDefaultQty() * 1 ?>" title="<?= __('Qty') ?>" class="input-text qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>" /--> <?php } ?> </div> </div> <?php endif; ?> <div class="actions"> <button type="submit" title="<?= /* @escapeNotVerified */ $buttonTitle ?>" class="action primary tocart" id="product-addtocart-button"> <span><?= /* @escapeNotVerified */ $buttonTitle ?></span> </button> <?= $block->getChildHtml('', true) ?> </div> </div> </div> <?php endif; ?> <?php if ($block->isRedirectToCartEnabled()) : ?> <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/product/view/validation": { "radioCheckboxClosest": ".nested" } } } </script> <?php else : ?> <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/js/validate-product": {} } } </script> <?php endif; ?> Another important file is Magento_ConfigurableProduct/web/js/configurable.js ...

February 16, 2018 · 9 min · Harshvardhan Malpani

Magento 2 temporary fix for Alphabetical sorting of Configurable product options

Just re-write the file vendor/magento/module-configurable-product/Model/ConfigurableAttributeData.php <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\ConfigurableProduct\Model; use Magento\Catalog\Model\Product; use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute; /** * Class ConfigurableAttributeData * @api * @since 100.0.2 */ class ConfigurableAttributeData { /** * Get product attributes * * @param Product $product * @param array $options * @return array */ public function getAttributesData(Product $product, array $options = []) { $defaultValues = []; $attributes = []; foreach ($product->getTypeInstance()->getConfigurableAttributes($product) as $attribute) { $attributeOptionsData = $this->getAttributeOptionsData($attribute, $options); if ($attributeOptionsData) { $productAttribute = $attribute->getProductAttribute(); $attributeId = $productAttribute->getId(); $attributes[$attributeId] = [ 'id' => $attributeId, 'code' => $productAttribute->getAttributeCode(), 'label' => $productAttribute->getStoreLabel($product->getStoreId()), 'options' => $attributeOptionsData, 'position' => $attribute->getPosition(), ]; $defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product); } } return [ 'attributes' => $attributes, 'defaultValues' => $defaultValues, ]; } public function labelsort($a,$b){ return strcmp($a['label'], $b['label']);} /** * @param Attribute $attribute * @param array $config * @return array */ protected function getAttributeOptionsData($attribute, $config) { $attributeOptionsData = []; foreach ($attribute->getOptions() as $attributeOption) { $optionId = $attributeOption['value_index']; $attributeOptionsData[] = [ 'id' => $optionId, 'label' => $attributeOption['label'], 'products' => isset($config[$attribute->getAttributeId()][$optionId]) ? $config[$attribute->getAttributeId()][$optionId] : [], ]; } if(count($attributeOptionsData) > 1){usort($attributeOptionsData,array($this,'labelsort'));} return $attributeOptionsData; } /** * @param int $attributeId * @param Product $product * @return mixed|null */ protected function getAttributeConfigValue($attributeId, $product) { return $product->hasPreconfiguredValues() ? $product->getPreconfiguredValues()->getData('super_attribute/' . $attributeId) : null; } }

February 16, 2018 · 2 min · Harshvardhan Malpani

Show Available Stock quantity for each product in Magento 2

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface'); echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId()); ?> Reference: https://magento.stackexchange.com/a/97952/32283

February 9, 2018 · 1 min · Harshvardhan Malpani

How to update Magento community edition using CLI

composer require magento/product-community-edition 2.2.6 --no-update composer update rm -rf var/di var/generation var/cache var/view_preprocessed generated/* php bin/magento cache:clean php bin/magento cache:flush php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento indexer:reindex php bin/magento deploy:mode:set production if you receive any errors post installation, try this hard fix rm -rf app/code/Magento/ var/* vendor/* chmod 777 -R * composer update && composer install php -f bin/magento setup:static-content:deploy find . -type d -exec chmod 775 {} find . -type f -exec chmod 660 {} chmod u+x bin/magento bin/magento maintenance:disable bin/magento cache:clean

February 1, 2018 · 1 min · Harshvardhan Malpani

How to shift category description below products in Magento 2

In your theme folder, add Folder Magento_Catalog/layout and in layout folder add file catalog_category_view.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <move element="category.view.container" after="content" destination="main.content" /> </body> </page>

January 29, 2018 · 1 min · Harshvardhan Malpani

How to add custom attributes in Magento 2 product CSV export

Core Method is to edit the file /vendor/magento/module-catalog-import-export/Model/Export/Product.php and Edit the variable $_exportMainAttrCodes Add your attributes in the array like “custom1″,”custom2”, etc and save the file. Next time you export the csv, you will see new columns in the file.

January 25, 2018 · 1 min · Harshvardhan Malpani