Osade tootja:
Dacia / Renault
this.$nextTick(() => {
if (typeof this.optionConfig.defaultValues === 'object') {
for (const [attributeId, value] of Object.entries(this.optionConfig.defaultValues)) {
this.changeOption(attributeId, value + '');
}
}
this.preselectQuerystringItems();
this.preselectLocationHashItems();
});
},
productIndex: 0,
productIndexForPrice: 0,
optionIsActive(attributeId, optionId) {
return !!this.getAllowedAttributeOptions(attributeId).find(
option => option.id === optionId
)
},
optionIsEnabled(attributeId, optionId) {
for (const productId in this.optionConfig.index) {
if (this.optionConfig.index[productId][attributeId] === optionId) {
return true;
}
}
return false;
},
findSimpleIndex() {
this.productIndex = this.calculateSimpleIndexForPartialSelection(this.selectedValues);
this.productIndexForPrice = this.findCheapestProductForPartialSelection(this.selectedValues);
},
calculateSimpleIndexForPartialSelection(selectedValues) {
if (selectedValues.length === 0) return 0;
return this.findProductIdsForPartialSelection(selectedValues)[0];
},
calculateSimpleIndexForFullSelection(selectedValues) {
if (! this.isFullSelection(selectedValues)) return false;
const productIndexes = this.optionConfig.index;
return Object.keys(productIndexes).find(productIndex => {
const productCandidateOptions = productIndexes[productIndex];
for (const productOption in productCandidateOptions) {
if (
!selectedValues[productOption] ||
selectedValues[productOption] !== productCandidateOptions[productOption]
) {
return false;
}
}
return productIndex;
});
},
findAllowedAttributeOptions() {
this.allowedAttributeOptions = this.calculateAllowedAttributeOptions(this.selectedValues);
},
calculateAllowedAttributeOptions(selectedValues) {
const allAttributes = this.optionConfig.attributes;
const allAttributesSorted = Object.values(allAttributes).sort((a,b) => {
return a.position - b.position
});
const newAllowedAttributeOptions = [];
allAttributesSorted.forEach(attribute => {
const selectionWithoutAttr = Object.assign({}, this.removeAttrFromSelection(selectedValues, attribute.id));
const availableIndexes = this.calculateAvailableProductIndexes(selectionWithoutAttr);
newAllowedAttributeOptions[attribute.id] = allAttributes[attribute.id].options.filter(option => {
return !!option.products.find(product => {
return availableIndexes.includes(product);
})
});
});
return newAllowedAttributeOptions;
},
calculateAvailableProductIndexes(selectedOptions) {
if (Object.keys(selectedOptions).length === 0) {
if (Object.values(this.optionConfig.salable || {}).length) {
return [].concat.apply([], [].concat.apply([], Object.values(this.optionConfig.salable).map(Object.values))).filter((x, i, a) => a.indexOf(x) === i)
}
return Object.keys(this.optionConfig.index);
}
const selectedIds = Object.keys(selectedOptions);
if (Object.values(this.optionConfig.salable || {}).length) {
const selectedOptionIndexes = selectedIds.map(attrId => {
const optionValue = selectedOptions[attrId];
return this.optionConfig.salable[attrId] && this.optionConfig.salable[attrId][optionValue] || []
})
return selectedOptionIndexes.reduce((acc, optionIndexes) => {
return acc.filter(index => optionIndexes.includes(index));
});
} else {
const productIndexes = this.optionConfig.index;
return Object.keys(productIndexes).filter(index => {
for (const attrId of selectedIds) {
if (productIndexes[index][attrId] !== `${selectedOptions[attrId]}`) return false
}
return true
});
}
},
findAttributeByOptionId(optionId) {
for (const attributeId in this.optionConfig.attributes) {
const attributeOptions = this.optionConfig.attributes[attributeId].options || [];
if (attributeOptions.find(option => option.id === optionId)) {
return attributeId;
}
}
},
getAllowedAttributeOptions(attributeId) {
return this.allowedAttributeOptions[attributeId] || []
},
getAllAttributeOptions(attributeId) {
return (
this.optionConfig.attributes[attributeId] &&
this.optionConfig.attributes[attributeId].options
) || []
},
getProductIdsForOption(option) {
const attributeId = this.findAttributeByOptionId(option.id);
const allOptions = this.optionConfig.attributes[attributeId];
const opt = (allOptions && allOptions.options || []).find(o => o.id === option.id);
return opt && opt.products
? opt.products
: [];
},
findProductIdsForPartialSelection(optionSelection) {
const candidateProducts = Object.values(optionSelection).reduce((candidates, optionId) => {
const newCandidates = this.getProductIdsForOption({id: optionId});
return candidates === null
? newCandidates
: candidates.filter(productId => newCandidates.includes(productId));
}, null);
return candidateProducts || [];
},
findCheapestProductForPartialSelection(optionSelection) {
const candidateProducts = this.findProductIdsForPartialSelection(optionSelection);
return candidateProducts.reduce((cheapest, simpleIdx) => {
// in the first iteration we start with simpleIdx as the currently cheapest product
if (! this.optionConfig.optionPrices[cheapest]) return simpleIdx;
const knownCheapestPrice = this.optionConfig.optionPrices[cheapest].finalPrice.amount;
return knownCheapestPrice > this.optionConfig.optionPrices[simpleIdx].finalPrice.amount
? simpleIdx
: cheapest;
}, 0)
},
findProductIdToUseForOptionPrice(option) {
// try to find a product for a complete selection
const attributeId = this.findAttributeByOptionId(option.id);
const optionSelection = Object.assign({}, this.selectedValues, {[attributeId]: option.id});
const matchingSimpleIndex = this.calculateSimpleIndexForFullSelection(optionSelection);
// if there is no complete selection, use the cheapest product for the option
return matchingSimpleIndex || this.findCheapestProductForPartialSelection(optionSelection);
},
getAttributeOptionLabel(option) {
const optionProduct = this.findProductIdToUseForOptionPrice(option);
if ((! optionProduct) || (optionProduct === this.productIndexForPrice)) {
return option.label;
}
const currentPrice = this.getOptionPriceAdjustmentBasePrice();
if (this.optionConfig.optionPrices[optionProduct]) {
const optionPrice = this.optionConfig.optionPrices[optionProduct].finalPrice.amount;
if (optionPrice !== currentPrice){
return option.label + ' ' + hyva.formatPrice(optionPrice - currentPrice, true);
}
}
return option.label;
},
getOptionPriceAdjustmentBasePrice() {
if (this.optionConfig.optionPrices[this.productIndexForPrice]) {
return this.optionConfig.optionPrices[this.productIndexForPrice].finalPrice.amount
}
return this.optionConfig.prices.finalPrice.amount; // default price if no option selection
},
clearOptionIfActive(optionId, value) {
if (this.selectedValues[optionId] === value) {
this.blurLabel()
this.changeOption(optionId, '')
}
},
removeAttrFromSelection(selectedValues, attributeId) {
attributeId = parseInt(attributeId);
return selectedValues.reduce((newSelection, val, attr) => {
if (attr !== attributeId) {
newSelection[attr] = val;
}
return newSelection;
}, []);
},
changeOption(attributeId, value) {
if (value === '') {
this.selectedValues = this.removeAttrFromSelection(this.selectedValues, attributeId)
} else if (value && this.getAllowedAttributeOptions(attributeId).find(option => option.id === value)) {
this.selectedValues[attributeId] = value;
}
this.findSimpleIndex();
this.findAllowedAttributeOptions();
this.updatePrices();
this.updateGallery();
const candidates = this.findProductIdsForPartialSelection(this.selectedValues);
window.dispatchEvent(
new CustomEvent(
'configurable-selection-changed',
{
detail: {
productId: this.productId,
optionId: attributeId,
value: value,
productIndex: this.productIndex,
selectedValues: this.selectedValues,
candidates: candidates,
skuCandidates: Object.values(candidates).map(id => this.optionConfig.sku[id]),
}
}
)
);
},
calculateIsMinimalPrice() {
return ! this.isFullSelection(this.selectedValues);
},
isFullSelection(selectedValues) {
return Object.values(selectedValues).length === Object.keys(this.optionConfig.attributes).length;
},
updatePrices() {
const value = this.optionConfig.optionPrices[this.productIndexForPrice] || this.optionConfig.prices;
window.dispatchEvent(
new CustomEvent(
"update-prices-" + this.productId,
{
detail: Object.assign(
value,
{ isMinimalPrice: this.calculateIsMinimalPrice() }
)
}
)
);
},
updateGallery () {
if (this.productIndex) {
const images = this.optionConfig.images[this.productIndex];
images && window.dispatchEvent(new CustomEvent(
"update-gallery",
{ detail: this.sortImagesByPosition(images) }
));
} else {
window.dispatchEvent(new Event("reset-gallery"));
}
},
sortImagesByPosition(images) {
return images.sort((x, y) => {
return x.position === y.position ? 0 : (parseInt(x.position) > parseInt(y.position) ? 1 : -1)
});
},
onGetCartData(data) {
},
preselectCartItems(data) {
// pre-select options based on cart data for current (quote) itemId
const cart = data && data.cart;
if (cart && cart.items) {
const cartItem = cart.items.find((item) => {
return (
item.item_id === this.itemId
&& item.product_id === this.productId
)
});
if (cartItem && cartItem.options && cartItem.options.length) {
cartItem.options.map(option => {
this.changeOption(option.option_id, option.option_value);
})
}
}
},
preselectQuerystringItems() {
// pre-select option like ?size=167
const urlQueryParams = new URLSearchParams(window.location.search.replace('?',''));
this.preselectItemsBasedOnLocation(attribute => urlQueryParams.get(attribute.code));
},
preselectLocationHashItems() {
// pre-select option like #144=167
const urlHashParams = new URLSearchParams(window.location.hash.replace('#',''));
this.preselectItemsBasedOnLocation(attribute => urlHashParams.get(attribute.id));
},
preselectItemsBasedOnLocation(getLocationValue) {
Object.values(this.optionConfig.attributes).map(attribute => {
const v = getLocationValue(attribute);
v && this.changeOption(attribute.id, v)
});
}
}
}
Leidke oma autole sobiv osa.
Varuosad + tootjad
Oil Filter PSA
Varuosad + tootja
Oil Filter Renault
Varuosad + artikli number
Oil Filter REN7700720978
Artikli number
7 700 720 978
Artikli number + tootjad
7 700 720 978 PSA
OEN + Manufacturers
0649007 SOFIMA