-
Notifications
You must be signed in to change notification settings - Fork 2
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
COR-2038 change fetch product image URL logic in catalog cron sync #190
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Model/Sync/Catalog/Data.php
Outdated
if (isset($attr['type']) && $attr['type'] === 'image') { | ||
$baseUrl = $this->yotpoCoreConfig->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); | ||
$data = $data ? $baseUrl . 'catalog/product' . $data : ""; | ||
if ($key == 'group_name' && $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case can be added to the switch case with inner if condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain how?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see this suggestion comment:
https://github.com/YotpoLtd/magento2-module-core/pull/190/files#r867898027
if ($key == 'group_name' && $value) { | ||
$value = strtolower($value); | ||
$value = str_replace(' ', '_', $value); | ||
$value = preg_replace('/[^A-Za-z0-9_-]/', '-', $value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this line do? It seems like everything regex search
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It replaces everything that is not alphanumeric, underscore, or dash with a dash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. Is this the expected behaviour? do we want it to replace !@#$%^&*()+= these for example to dash?
Model/Sync/Catalog/Data.php
Outdated
|
||
$method = $attr['method']; | ||
$itemValue = $this->$method($item, $configKey); | ||
$value = $itemValue ?: ($method == 'getProductPrice' ? 0.00 : $itemValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be reduced to one oneliner condition intead of nested condition
6d8150b
to
1203c01
Compare
|
||
if (isset($attr['type']) && $attr['type'] === 'url') { | ||
$data = $item->getProductUrl(); | ||
switch ($attributeKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch ($attributeKey) { | |
$attributeDataValue = ''; | |
$attributeDetailsAttributeCode = ''; | |
$attributeDetailsMethod = $attributeDetails['method']; | |
if (isset($attributeDetails['attr_code']) && $attributeDetails['attr_code']) { | |
$attributeDetailsAttributeCode = $attributeDetails['attr_code']; | |
} | |
$itemValue = $this->$attributeDetailsMethod($item, $attributeDetailsAttributeCode); | |
switch ($attributeKey) { | |
case 'gtins': | |
$attributeDataValue = $this->prepareGtinsData($attributeDetails, $item); | |
break; | |
case 'custom_properties': | |
$attributeDataValue = $this->prepareCustomProperties($attributeDetails, $item); | |
break; | |
case 'is_discontinued': | |
$attributeDataValue = false; | |
break; | |
case 'url': | |
$attributeDataValue = $item->getProductUrl(); | |
break; | |
case 'image_url': | |
$attributeDataValue = $this->getProductImageUrl($item); | |
break; | |
case 'group_name': | |
if ($itemValue) { | |
$attributeDataValue = substr((string)$itemValue, 0, 100); | |
$attributeDataValue = strtolower($attributeDataValue); | |
$attributeDataValue = str_replace(' ', '_', $attributeDataValue); | |
$attributeDataValue = preg_replace('/[^A-Za-z0-9_-]/', '-', $attributeDataValue); | |
} | |
break; | |
default: | |
if (!$attributeDetails['default'] && isset($attributeDetails['method']) && $attributeDetails['method']) { | |
if ($itemValue) { | |
$attributeDataValue = $itemValue; | |
} elseif ($attributeDetailsMethod == 'getProductPrice') { | |
$attributeDataValue = 0.00; | |
} else { | |
$attributeDataValue = $itemValue; | |
} | |
} | |
} | |
$itemAttributesData[$attributeKey] = $attributeDataValue; | |
if (($attributeKey == 'custom_properties' || $attributeKey == 'gtins') && !$attributeDataValue) { | |
unset($itemAttributesData[$attributeKey]); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this change. You've basically extracted what we had in the default
clause, but it's not relevant for all of the action types.
It looks better for sure, but it degregates performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with that. Because default clause shouldn't check for other cases. Its a bad practice.
But I agree on the performance concern. I created a new branch with a refactor commit so it will be better performance wise (and easier for you to read than a suggestion). Let me know what you think. We can also talk about it in a call.
7f554dc
if ($itemValue) { | ||
$value = $itemValue; | ||
} elseif ($method == 'getProductPrice') { | ||
$value = 0.00; | ||
} else { | ||
$value = $itemValue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we changed the logic now no? Isn't it should be:
if ($itemValue) { | |
$value = $itemValue; | |
} elseif ($method == 'getProductPrice') { | |
$value = 0.00; | |
} else { | |
$value = $itemValue; | |
} | |
if ($method == 'getProductPrice') { | |
$value = 0.00; | |
} else { | |
$value = $itemValue; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that your suggestion is the one changing the logic.
The one I wrote broke down the one-liner we had there.
According to what you wrote, all getProductPrice
will get a value of 0.00
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, my bad. maybe lets change it then to:
if (!$itemValue && $method == 'getProductPrice') {
$value = 0.00;
} else {
$value = $itemValue;
}
the three ifs condition is confusing. wdyt?
No description provided.