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 issue productlist image not shown when child product image empty … #3397

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Invalid Discount code error handled by theme - @grimasod (#3385)
- Fallback for empty value or no_selection child image - @ngongoll (#3397)
- `order.order_id` was not assigned in the `orders.directBackendSync` mode - @pkarw (#3398)
- Hydration problems with UrlDispatcher :rocket: - @patzick (#3412)

Expand Down
15 changes: 12 additions & 3 deletions core/modules/catalog/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ function _filterRootProductByStockitem (context, stockItem, product, errorCallba
}
}

/**
* check if object have an image
*/
export const hasImage = (product) => product && product.image && product.image !== 'no_selection'
/**
* check if one of the configuableChildren has an image
*/
export const childHasImage = (children = []) => children.some(hasImage)

export function findConfigurableChildAsync ({ product, configuration = null, selectDefaultChildren = false, availabilityCheck = true }) {
let selectedVariant = product.configurable_children.find((configurableChild) => {
if (availabilityCheck) {
Expand Down Expand Up @@ -489,7 +498,7 @@ export function configureProductAsync (context, { product, configuration, select
Logger.debug('Skipping configurable options setup', configuration)()
} */
const fieldsToOmit = ['name']
if (selectedVariant.image === '') fieldsToOmit.push('image')
if (!hasImage(selectedVariant)) fieldsToOmit.push('image')
selectedVariant = omit(selectedVariant, fieldsToOmit) // We need to send the parent SKU to the Magento cart sync but use the child SKU internally in this case
// use chosen variant
if (selectDefaultVariant) {
Expand Down Expand Up @@ -567,11 +576,11 @@ export function attributeImages (product) {

export function configurableChildrenImages (product) {
let configurableChildrenImages = []
if (product.configurable_children && product.configurable_children.length > 0) {
if (this.childHasImage(product.configurable_children)) {
let configurableAttributes = product.configurable_options.map(option => option.attribute_code)
configurableChildrenImages = product.configurable_children.map(child =>
({
'src': getThumbnailPath(child.image, config.products.gallery.width, config.products.gallery.height),
'src': getThumbnailPath((!hasImage(child) ? product.image : child.image), config.products.gallery.width, config.products.gallery.height),
'loading': getThumbnailPath(product.image, config.products.thumbnails.width, config.products.thumbnails.height),
'id': configurableAttributes.reduce((result, attribute) => {
result[attribute] = child[attribute]
Expand Down