-
-
Save bryanleetc/5886043eadc14e8d18000a08459c9c81 to your computer and use it in GitHub Desktop.
Snippet to be pasted in console in product details page to get data for the product widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bryan's version | |
let product = window.App.payload.product || {}; | |
function getDetails() { | |
const transformedPrice = product.price_range.max === product.price_range.min ? `$${product.price_range.min}` : `$${product.price_range.min} - $${product.price_range.max}`; | |
return { | |
title: product.title, | |
supply_id: product.id, | |
price: `US${transformedPrice}`, | |
supplier: product.supplier.name, | |
image: product.image.path, | |
aliexpress: product.link && product.link.includes('aliexpress') || false, | |
sales: product.total_orders_count, | |
}; | |
} | |
copy(getDetails()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
price = cleanPrice(); | |
supply_id = window.location.pathname.split('/')[4]; | |
title = $('.-margin-left-md > h3')[0].innerText; | |
supplier = $('.product-options__value:has(a)')[0].firstChild.text; | |
image = $('.img-container-extra-lg')[0].firstChild.src; | |
aliexpress = false; | |
function cleanPrice(){ | |
price = $('.product-options__price')[0].innerText; | |
if (price.indexOf('%') > 0) { | |
price = price.substring(0, price.indexOf('%') - 2) | |
} | |
return price | |
} | |
function getDetails() { | |
if(window.location.pathname.split('/')[4] == undefined){ | |
supply_id = window.location.pathname.split('/')[2]; | |
aliexpress = true; | |
} | |
return {supply_id, title, price, supplier, image, aliexpress} | |
}; | |
getDetails(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment