SCP module in magento – How to pass custom attribute into SCP module JSON

SCP magento – How to pass custom attribute values :
When you use SCP module for simple & configurable product, some time you have to pass your custom attribute values. Here i will explain how you want to pass your custom values. When you choose the configurable attribute dropdown the price and image or etc… of associate product values will change and it will show in frontend. SCP module will fetch all the information into one JSON when configurable product page load time. Whenever you choose the dropdown value then the value will chagen (like price or gallery or description or shortdescription). In this JSON you want to pass your custom values ? Yes we can, for this we have to check only two files, use below two files,

OrganicInternet\SimpleConfigurableProducts\Catalog\Block\Product\View\Type\Configurable.php
Here we will all the associated product id & detail, code like below

$childProducts[$productId] = array(
“price” => $this->_registerJsPrice($this->_convertPrice($product->getPrice())),
“finalPrice” => $this->_registerJsPrice($this->_convertPrice($product->getFinalPrice())),
“my_custom_attribute1” => 100,
“my_custom_attribute2” => 500
);

from the above code am passing two custom “my_custom_attribute1”, “my_custom_attribute2”. Value is 100 & 500.

How you have to get this custom attribute value from JS file, we have use below way, add below code into your scp_product_extension.js file,

childProducts[childProductId][“my_custom_attribute1”]
childProducts[childProductId][“my_custom_attribute2”]

just alert the value in your js file, you will get the value of “my_custom_attribute1”, “my_custom_attribute2”
default\js\scp_product_extension.js

Based on above two attribute am calculating my custom price like below

optionsPrice.productPrice = finalPrice * my_custom_attribute1;
optionsPrice.productOldPrice = price * my_custom_attribute1;

Cleare cache and run it.

Leave a Reply