@@ -402,47 +402,52 @@ protected function getProductListingsForStore(
402
402
'image_url ' => $ this ->getBaseImageUrl () . $ this ->getCustomAttribute ($ item ,$ this ->getImageUrlKey ())
403
403
);
404
404
405
- $ tmp = $ this ->appendPricing ($ id , $ tmp , $ store_currency , $ base_currency );
405
+ $ tmp = $ this ->appendPricing ($ id , $ tmp , $ storeId , $ base_currency, $ store_currency );
406
406
407
407
$ store_listings [$ id ][$ storeId ] = $ tmp ;
408
408
}
409
409
410
410
return $ store_listings ;
411
411
}
412
412
413
- protected function appendPricing ($ product_id , $ item , $ store_currency = null , $ base_currency= null ){
414
-
413
+ protected function appendPricing ($ product_id , $ item , $ storeId = null , $ base_currency = null , $ store_currency = null )
414
+ {
415
415
$ store_price = $ this ->getProductPrice (
416
416
$ product_id ,
417
- $ item ,
417
+ $ storeId ,
418
418
\Magento \Catalog \Pricing \Price \RegularPrice::PRICE_CODE ,
419
- $ store_currency ,
420
- $ base_currency );
419
+ $ base_currency ,
420
+ $ store_currency
421
+ );
422
+
423
+ if ($ store_price ) {
424
+ $ item ['price ' ] = $ store_price ;
425
+ }
421
426
422
427
$ store_special_price = $ this ->getProductPrice (
423
428
$ product_id ,
424
- $ item ,
429
+ $ storeId ,
425
430
\Magento \Catalog \Pricing \Price \SpecialPrice::PRICE_CODE ,
426
- $ store_currency ,
427
- $ base_currency );
431
+ $ base_currency ,
432
+ $ store_currency
433
+ );
428
434
429
- $ item ['price ' ] = $ store_price ;
435
+ if ($ store_special_price ) {
436
+ $ item ['special_price ' ] = $ store_special_price ;
437
+ }
430
438
431
439
if ($ this ->_request ->getParam ('final_price ' ) === 'true ' ) {
432
440
$ store_final_price = $ this ->getProductPrice (
433
441
$ product_id ,
434
- $ item ,
442
+ $ storeId ,
435
443
\Magento \Catalog \Pricing \Price \FinalPrice::PRICE_CODE ,
436
- $ store_currency ,
437
- $ base_currency );
438
-
439
- $ item ['final_price ' ] = $ store_final_price ;
440
- }
444
+ $ base_currency ,
445
+ $ store_currency
446
+ );
441
447
442
- if ($ store_special_price ) {
443
- $ item ['special_price ' ] = $ store_special_price ;
444
- //$item['special_price_dt_from'] = null;
445
- //$item['special_price_dt_to'] = null;
448
+ if ($ store_final_price ) {
449
+ $ item ['final_price ' ] = $ store_final_price ;
450
+ }
446
451
}
447
452
448
453
return $ item ;
@@ -451,20 +456,26 @@ protected function appendPricing($product_id, $item, $store_currency=null, $base
451
456
452
457
protected function getProductPrice (
453
458
$ product_id ,
454
- $ item ,
459
+ $ storeId ,
455
460
$ price_code ,
456
- $ store_currency =null ,
457
- $ base_currency =null
458
- ){
459
- $ product = $ this ->productRepository ->getById ($ product_id );
460
- $ price = $ product ->getPriceInfo ()->getPrice ($ price_code )->getValue ();
461
+ $ base_currency = null ,
462
+ $ store_currency = null
463
+ ) {
464
+ $ product = $ this ->productRepository ->getById ($ product_id , false , $ storeId );
461
465
462
- if ($ store_currency && $ base_currency ){
463
- $ price = $ this ->directoryHelper ->currencyConvert (
464
- $ price ,
465
- $ base_currency ,
466
- $ store_currency
466
+ $ price = $ product ->getPriceInfo ()->getPrice ($ price_code )->getValue ();
467
+
468
+ if ($ store_currency && $ base_currency ) {
469
+ try {
470
+ $ price = $ this ->directoryHelper ->currencyConvert (
471
+ $ price ,
472
+ $ base_currency ,
473
+ $ store_currency
467
474
);
475
+ } catch (\Exception $ e ) {
476
+ $ a = true ;
477
+ // Allow the "undefined rate" exception and return the price as is if no rate has been setup.
478
+ }
468
479
}
469
480
470
481
return $ price ;
0 commit comments