Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing attributeValues and autoselect config errors #530

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions resources/js/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,6 @@ Vue.prototype.updateCart = async function (data, response) {
}
cart.value = 'cart' in Object.values(response.data)[0] ? Object.values(response.data)[0].cart : Object.values(response.data)[0]

getAttributeValues().then((response) => {
if (!response?.data?.customAttributeMetadata?.items) {
return
}

const mapping = Object.fromEntries(
response.data.customAttributeMetadata.items.map((attribute) => [
attribute.attribute_code,
Object.fromEntries(attribute.attribute_options.map((value) => [value.value, value.label])),
]),
)

cart.value.items = cart.value.items.map((cartItem) => {
cartItem.product.attribute_values = {}

for (const key in mapping) {
cartItem.product.attribute_values[key] = cartItem.product[key]
if (cartItem.product.attribute_values[key] === null) {
continue
}

if (typeof cartItem.product.attribute_values[key] === 'string') {
cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].split(',')
}

if (typeof cartItem.product.attribute_values[key] !== 'object') {
cartItem.product.attribute_values[key] = [cartItem.product.attribute_values[key]]
}

cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].map((value) => mapping[key][value] || value)
}

return cartItem
})
})

return response.data
}

Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/Elements/Slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export default {
let slide = this.childSpan == 0 ? 0 : this.currentSlide

this.childSpan = this.vertical
? this.container.children[0]?.offsetHeight ?? this.container.offsetHeight
: this.container.children[0]?.offsetWidth ?? this.container.offsetWidth
? (this.container.children[0]?.offsetHeight ?? this.container.offsetHeight)
: (this.container.children[0]?.offsetWidth ?? this.container.offsetWidth)

this.navigate(slide, 'instant')

Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/Product/AddToCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default {
return addition
},
async setDefaultOptions() {
if (!window.config.add_to_cart.auto_select_configurable_options || !window.config.product?.super_attributes) {
if (!window.config.add_to_cart?.auto_select_configurable_options || !window.config.product?.super_attributes) {
return
}
// We do not loop and use the values of enabledOptions directly.
Expand All @@ -230,7 +230,7 @@ export default {
})
},
async setDefaultCustomSelectedOptions() {
if (!window.config.add_to_cart.auto_select_product_options || !window.config.product?.options) {
if (!window.config.add_to_cart?.auto_select_product_options || !window.config.product?.options) {
return
}

Expand Down
52 changes: 46 additions & 6 deletions resources/js/stores/useCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,53 @@ export const cart = computed({
return cartStorage.value
},
set(value) {
cartStorage.value = value
age = Date.now()
getAttributeValues()
.then((response) => {
if (!response?.data?.customAttributeMetadata?.items) {
return
}

if (value.id && value.id !== mask.value) {
// Linking user to cart will create a new mask, it will be returned in the id field.
mask.value = value.id
}
const mapping = Object.fromEntries(
response.data.customAttributeMetadata.items.map((attribute) => [
attribute.attribute_code,
Object.fromEntries(attribute.attribute_options.map((value) => [value.value, value.label])),
]),
)

value.items = value.items.map((cartItem) => {
cartItem.product.attribute_values = {}

for (const key in mapping) {
cartItem.product.attribute_values[key] = cartItem.product[key]
if (cartItem.product.attribute_values[key] === null) {
continue
}

if (typeof cartItem.product.attribute_values[key] === 'string') {
cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].split(',')
}

if (typeof cartItem.product.attribute_values[key] !== 'object') {
cartItem.product.attribute_values[key] = [cartItem.product.attribute_values[key]]
}

cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].map(
(value) => mapping[key][value] || value,
)
}

return cartItem
})
})
.finally(() => {
cartStorage.value = value
age = Date.now()

if (value.id && value.id !== mask.value) {
// Linking user to cart will create a new mask, it will be returned in the id field.
mask.value = value.id
}
})
},
})

Expand Down
4 changes: 1 addition & 3 deletions src/Models/Scopes/ForCurrentStoreWithoutLimitScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/
class ForCurrentStoreWithoutLimitScope implements Scope
{
public function __construct(public $uniquePerStoreKey, public $storeIdColumn = 'store_id')
{
}
public function __construct(public $uniquePerStoreKey, public $storeIdColumn = 'store_id') {}

public function apply(Builder $query, Model $model)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Rapidez.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Rapidez
{
protected string|bool|null $compadreVersion;

public function __construct(protected Collection $routes)
{
}
public function __construct(protected Collection $routes) {}

public function addFallbackRoute($action, $position = 9999)
{
Expand Down
Loading