MISCONF Redis is configured to save RDB snapshots

Have you ever faced following problem on the server because of the redis?

MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error

We recently faced this error on our client’s live site server. Here is the solution for the same:

You will need to login into your server using SSH and hit following commands.

$ redis-cli
> config set stop-writes-on-bgsave-error no

I hope these command solve your problem and let us know if you have other solution which worked for you.

Happy coding guys!

How to change price dynamically on product page in Magento2

In this blog post, we are going to code how to dynamically change the price on product page for magento 2.

To add JS code on the product page, we have created layout file and added js file in content reference container.

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template"
               name="pricechange" as="pricechange" template="Codedecorator_Learn::product/js.phtml"/>
    </referenceContainer>
</page>

After creating layout file, lets create template file which will have our js code

require(["jquery","Magento_Catalog/js/price-utils"], function(jQuery,priceUtils) {
    var productPrice = parseFloat(jQuery('span.price-final_price > span[data-price-type="finalPrice"]').attr('data-price-amount'));
    var finalPrice=100;
    formatedPrice = priceUtils.formatPrice(parseInt(finalPrice));
    jQuery('span.price-final_price > span.price-wrapper > span.price').text(formatedPrice);
    var finalPrice=productPrice+(pricePerText*textObjects)+(pricePerImage*imageObjects);
    formatedPrice = priceUtils.formatPrice(parseInt(finalPrice));
    jQuery('span.price-final_price > span.price-wrapper > span.price').text(formatedPrice);
}); // Required

After creating both the files, just flush the cache using following command.

php bin/magento cache:flush

I hope this post will help and give the solution for any of your problem.

happy coding 😀

How to rewrite widget function with mixins Magento 2

In this post, we will understand how to use Mixins in Magento 2.

What is Mixin?

Mixins are a language concept that allows a programmer to inject some code into a class

A mixin is a class containing methods that can be used by other classes without a need to inherit from it.

Wikipedia

If we want to perform an extra action or extend a Javascript functionality without completely overwriting it, in this case mixin comes in picture. Let’s start with an example

var config = {
    config: {
        mixins: {
            'Magento_Catalog/js/catalog-add-to-cart': {
                'Codedecorator_Learn/js/cd-catalog-add-to-cart-mixin': true
            }
        }
    }
};

After creating above file, we need to create cd-catalog-add-to-cart-mixin.js file where we will extend the functionality of the submitForm function.

define([
], function () {
    'use strict';
    return function (widget) {
        $.widget('mage.catalogAddToCart', widget, {
            /**
             * Handler for the form 'submit' event
             *
             * @param {jQuery} form
             */
            submitForm: function (form) {
                this.ajaxSubmit(form); // original code
                this.doSomethingAfterSubmit(); // add every thing you want
            },
            /**
             * Do something
             */
            doSomethingAfterSubmit: function () {
                // Do stuff
            },
        });
        return $.mage.catalogAddToCart;
    }
});

Try to add product into cart and see your change is coming in or not. If not then try to flush cache or deploy the content.

Happy coding guys 😀