where is the path of opConfig.reloadPrice(); in magento - magento

i need to customize function opConfig.reloadPrice(); in magento.
can anyone tell me where is that function locate?
This function is executed on custom attribute drop down on product details page.
As i need to change the Special price calculation , i guess need to customize this function .

This method can be found in following files:
grep 'reloadPrice:' . -rsn
./js/varien/configurable.js:271: reloadPrice: function()
./js/varien/product.js:463: reloadPrice: function()
./skin/frontend/base/default/js/bundle.js:83: reloadPrice: function()

For change custom option value, you should change in to js/varient/product.js
and in that page you found, reload:function()
that function call at the time of on change event.
Good Luck

I also had the issue of having to change the default behaviour of Magento on this one. I included jQuery in my project and I finaly figured it out by first removing the default behavior of Magento and instead on calculatePrice call my calculatePrices()-function:
$j('#select_20, #select_21').removeAttr('onchange').change(function(){
calculatePrices();
});
Now, in this calculatePrices()-function, alongside with some other logic, I included this to change the prices:
function calculatePrices()
{
var price = 0;
// some logic with custom options, not interesting for this question...
// Change the price according to the options:
$j('#select_20, #select_21').each(function(){
var selectId = this.id.replace('select_', '');
var options = opConfig.config[selectId][this.value];
if(options.type == 'fixed') {
price += options.priceValue;
} else {
// percentual change:
price += price * (options.priceValue/100);
}
});
// Use Magento Objects to set these prices:
optionsPrice.changePrice('bundle', price);
optionsPrice.reload();
}

Related

Magento 2 calculate product price against user input

I am currently trying to implement some extra product price attribute which will take user input and calculate the price according to that. Tried with price attribute but not working. Any idea how to do it, as new in magento unable to fix that. Please note height and width are input type text, a user can add any value
To achieve this, i have created a set of attributes in admin section,
From the front end trying to calculate the price,
require([
'jquery','Magento_Catalog/js/price-utils','jquery/ui','Magento_Catalog/js/price-box'
], function($,priceUtils,priceBox){
"use strict";
var priceBoxes = $('[data-role=priceBox]');
$('.product-custom-optionval').change(function () {
var value = $(this).val();
if (value === '') {
$(this).val(0);
updatePriceOnChange(0, $(this).attr('data-attr-id'));
return;
}
disableAddToCartBtn('#product_addtocart_form');
calculatePrice($(this));
enableAddToCartBtn('#product_addtocart_form');
});
****** But after calculating the price what will my approach to update product price, please help *******
HI for this you can do something like
Create custom module
Define custom controller
whenever user puts the input in the height and width
Send those parameters to the controller along with the product id and qty
Do your calculations there on basis of your logic and return response
upadte the price in the div on basis of the response
than when user hits add to cart , listen before add to cart event and upadte the cart item price with the new price of your calculations
rest magento will do itself
hope that will help you somehwere

Success message won't disappear in the home page Magento 2

When I try to use the LUMA Theme, the success message is working properly, but when I use the custom theme, that's where the problem starts. The success message accumulates in the home page whenever I try to add a product to the compare list. I'm using Magento 2.1.3. See the picture below:
Seems your's theme do some thing with section update process on frontend. You should look at file
vendor/magento/module-customer/view/frontend/web/js/view/customer.js
and add condition and do force refresh of the sections
define([
'uiComponent',
'Magento_Customer/js/customer-data'
], function (Component, customerData) {
'use strict';
return Component.extend({
initialize: function () {
this._super();
var someCondition = true;
this.customer = customerData.get('customer');
if(someCondition === true){
customerData.reload(['customer']);
}
}
});
});

Big Cartel cart

I have made a custom theme on big cartel, and everything is perfect, except one thing.
I would like to have the cart update without going to the cart page when adding an item to your cart.
I have made my custom template over the "sexy" theme and have no idea how I go about implanting this
I know this can be done, because default themes like "Good Vibes" do this.
You can use the code below. I didn't include the code for the restoreButton function in the addItem callback but I'm sure you get the idea. You'll also need your own means of retrieving the product ID based on however you're displaying your product options. Make sure to also include a reference to Big Cartel's javascript api.
$('#add_to_bag').click(function(evt){
var productId;
if($('.options_select').length != 0)
productId = $( ".options_select option:selected" ).attr('value');
else
productId = $('.price_options input').attr('value');
var quantity = $('.quantity input').attr('value');
Cart.addItem(productId, quantity, function(cart) {
$('#add_to_bag').attr('value', 'Item Added');
setTimeout(restoreButton, 2000);
});
});
You'll want to take advantage of the javascript API: https://help.bigcartel.com/developers/themes/#javascript-api
With this, you can drop in the line of code to load the API into your theme and have access to add, update, and remove items from the cart using javascript.

Wordpress Create Category AJAX Response

I currently have a plugin that allows a user to activate/deactivate categories to drive a menu. I've created an option for the toggle and have it functioning in the create form and edit form seamlessly. The only place I can't seem to add it is to the AJAX return from wordpress when the category is created. I can create the column when the Categories page is loaded but don't know how to tap into the AJAX Return without modifying the core. Is there a hook that I'm unaware of that allows you to modify this return?
Using Akmal's answer, this is my script to check if the Taxonomy-Category was created or not.
Thanks Akmal.
Wordpress version 3.8.2
$(document).ajaxComplete(function(event, xhr, settings) {
var queryStringArr = settings.data.split('&');
if( $.inArray('action=add-tag', queryStringArr) !== -1){
var xml = xhr.responseXML;
$response = $(xml).find('term_id').text();
if($response!=""){
console.log('This is the action.');
}
}
});
Do you try to run some Javascript after ajax return (after add new category)?
Try to put below code in your code when you create the custom field in category form :
$(document).ajaxComplete(function(event, xhr, settings) {
var queryStringArr = settings.data.split('&');
if ($.inArray('action=add-tag', queryStringArr) !== -1){
your_javascript_function(); //this is your js function
}
});

jQuery stops working after ajax request that adds fields to a form in Drupal 7

I don't think this is a Drupal-specific question, but more of a general jquery/ajax issue:
Basically, I'm trying to use javascript to add up form fields and display the result in a "subtotal" field within the same form. Everything is working fine until i click the option to add another field (via ajax), which then changes my "subtotal" field to zero, and won't work again until I remove the field.
Here is the function that adds up the fields:
function calculateInvoiceFields(){
var total = 0;
var rate = 0;
var quantity = 0;
var i = 0;
var $ = jQuery;
$("#field-aminvoice-data-values tr").each(function(){
// quantity field number
quantity = $("#edit-field-aminvoice-data-und-"+i+"-field-aminvoice-quantity-und-0-value").val();
// rate field as number
rate = $("#edit-field-aminvoice-data-und-"+i+"-field-aminvoice-rate-und-0-value").val();
if(!isNaN(quantity) && !isNaN(rate)){
total += quantity*rate;
}
i++;
});
return total;
}
And here are the functions that get fired for .ready and .live:
jQuery(document).ready(function(){
var $ = jQuery;
$(".field-type-commerce-price input").val(calculateInvoiceFields());
});
jQuery(function(){
var $ = jQuery;
$(".form-text").live('change', function(){
$(".field-type-commerce-price input").val(calculateInvoiceFields());
});
});
Any ideas would be a big help. Thanks in advance!
I recommend using 'on' for any binding statement. and 'off' for unbinding.
The reason it doesn't work after an AJAX call, is because you need to be watching for that element to be added to the DOM, and an event attached to it after it gets loaded. If you load a new element in, and there is nothing watching for it, it won't add the event watch to that new DOM element.
As below:
function calculateInvoiceFields(){
/*..*/
return total;
}
$(document).ready(function(){
$(".field-type-commerce-price input").val(calculateInvoiceFields());
$("body").on('change', ".form-text", function(){
$(".field-type-commerce-price input").val(calculateInvoiceFields());
});
});
usually it stops working when an error has been thrown. did you check out your javascript console (firefox firebug, or built in for chrome) for any indication of an error?

Resources