@@ -34,14 +34,13 @@ class BestBuy extends StoreTemplate
3434 public function __construct (Link $ link , array $ extra_headers = [], ?string $ user_agent = '' )
3535 {
3636
37- // if ($this->link->store->domain === "bestbuy.ca") {
38- // $this->chromium_crawler = true;
39- // $this->extra_headers = $extra_headers + ['X-CLIENT-ID' => 'lib-price-browser'] + $this->extra_headers;
40- // } else {
41- $ this ->extra_headers = $ extra_headers + $ this ->extra_headers ;
42- // }
43-
44- $ this ->user_agent = ($ user_agent ) ?: UserAgentHelper::get_random_user_agent ();
37+ if ($ link ->store ->domain === "bestbuy.ca " ) {
38+ $ this ->chromium_crawler = true ;
39+ $ this ->extra_headers = $ extra_headers + ['X-CLIENT-ID ' => 'lib-price-browser ' ] + $ this ->extra_headers ;
40+ } else {
41+ $ this ->extra_headers = $ extra_headers + $ this ->extra_headers ;
42+ $ this ->user_agent = ($ user_agent ) ?: UserAgentHelper::get_random_user_agent ();
43+ }
4544
4645 parent ::__construct ($ link );
4746 }
@@ -62,7 +61,7 @@ public static function prepare_url(Link $link, array $extra = []): string
6261 return Str::replace (
6362 ["[domain] " , "[product_key] " ],
6463 [$ link ->store ->domain , $ link_base ],
65- ($ link ->store ->domain == "bestbuy.com " ) ? self ::MAIN_URL : self ::CANADA_URL ) ."? {$ link_params }" ;
64+ ($ link ->store ->domain == "bestbuy.com " ) ? self ::MAIN_URL : self ::CANADA_URL )."? {$ link_params }" ;
6665 }
6766
6867 public function get_name (): void
@@ -78,6 +77,7 @@ public function get_image(): void
7877 {
7978 $ ids_and_tag_selector = [
8079 '.pdp-media-gallery img:first-child ' ,
80+ '[class^="mediaGalleryGridArea"] img:first-child ' ,
8181 ];
8282 $ results = $ this ->dom ->querySelectorAll (implode (', ' , $ ids_and_tag_selector ));
8383
@@ -87,7 +87,7 @@ public function get_image(): void
8787
8888 foreach ($ attributes as $ attribute ) {
8989 $ image_url = $ results [0 ]?->getAttribute($ attribute );
90- if (! empty ($ image_url )) {
90+ if (filled ($ image_url )) {
9191 $ this ->product_data ['image ' ] = explode ('; ' , $ image_url )[0 ];
9292 break ;
9393 }
@@ -143,12 +143,20 @@ public function get_price(): void
143143 '#corePrice_feature_div span.a-price-fraction ' ,
144144 ];
145145
146+ $ full_price_selectors = [
147+ '[class^="style-module_price_"] ' ,
148+ ];
149+
146150 $ results_whole = $ this ->dom ->querySelectorAll (implode (', ' , $ whole_price_selectors ));
147151 $ results_fraction = $ this ->dom ->querySelectorAll (implode (', ' , $ fractional_price_selectors ));
152+ $ full_price_results = $ this ->dom ->querySelectorAll (implode (', ' , $ full_price_selectors ));
148153
149154 $ only_whole = GeneralHelper::get_numbers_only ($ results_whole [0 ]?->textContent);
150155 $ this ->product_data ['price ' ] = (float ) "{$ only_whole }. {$ results_fraction [0 ]?->textContent}" ;
151156
157+ if (! $ this ->product_data ['price ' ]) {
158+ $ this ->product_data ['price ' ] = (float ) GeneralHelper::get_numbers_only_with_dot ($ full_price_results [0 ]?->textContent);
159+ }
152160 }
153161
154162 public function get_used_price (): void
0 commit comments