pagantis /
woocommerce
| 1 | /* global variationSimulatorData */ |
||
| 2 | |||
| 3 | if (typeof variationSimulatorData == 'undefined'){ |
||
| 4 | throw new Error("variationSimulatorData is undefined"); |
||
| 5 | } |
||
| 6 | |||
| 7 | window.lastPrice = ''; |
||
| 8 | function updateSimulator() |
||
| 9 | { |
||
| 10 | if (window.WCSimulatorId !== '') |
||
|
0 ignored issues
–
show
|
|||
| 11 | { |
||
| 12 | var updateSelector = variationSimulatorData.variationSelector; |
||
| 13 | if (updateSelector === 'default') { |
||
| 14 | updateSelector = 'div.woocommerce-variation-price span.price span.woocommerce-Price-amount'; |
||
| 15 | } |
||
| 16 | |||
| 17 | var productType = variationSimulatorData.productType; |
||
| 18 | |||
| 19 | if (productType !=='variable') |
||
| 20 | { |
||
| 21 | clearInterval(window.variationInterval); |
||
|
0 ignored issues
–
show
|
|||
| 22 | } |
||
| 23 | else |
||
| 24 | { |
||
| 25 | var priceDOM = document.querySelector(updateSelector); |
||
| 26 | if (priceDOM != null) { |
||
|
0 ignored issues
–
show
|
|||
| 27 | var newPrice = priceDOM.innerText; |
||
| 28 | if (newPrice !== window.lastPrice) { |
||
|
0 ignored issues
–
show
There is no return statement if
newPrice !== window.lastPrice is false. Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
Loading history...
|
|||
| 29 | window.lastPrice = newPrice; |
||
| 30 | window.pgSDK.simulator.update(window.WCSimulatorId, {itemAmountSelector: updateSelector}) |
||
| 31 | } |
||
|
0 ignored issues
–
show
|
|||
| 32 | } else { |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | window.variationInterval = setInterval(function () { |
||
| 39 | updateSimulator(); |
||
| 40 | }, 5000); |
This check looks for functions where a
returnstatement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBigwill only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined.This behaviour may not be what you had intended. In any case, you can add a
return undefinedto the other execution path to make the return value explicit.