ASIN ?? null ) : ( $item->asin ?? null ); if ( ! is_string( $asin ) || ! preg_match( '/^[A-Z0-9]{10}$/D', $asin ) ) { return null; } $title = $service ? ( $item->title ?? null ) : ( $legacy ? ( $item->ItemInfo->Title->DisplayValue ?? null ) : ( $item->itemInfo->title->displayValue ?? null ) ); $image = $service ? ( $item->image_url ?? null ) : ( $legacy ? ( $item->Images->Primary->Large->URL ?? null ) : ( $item->images->primary->large->url ?? null ) ); return array( 'sku' => $asin, 'pid' => 'AZ' . $asin, 'title' => is_string( $title ) ? $title : '', 'image' => is_string( $image ) ? $image : '', 'merchant' => array(), '_afx_unavailable_asin' => $asin ); } public static function api( $item, $legacy = false ) { $container = $legacy ? ( $item->OffersV2 ?? null ) : ( $item->offersV2 ?? null ); $listings = $legacy ? ( $container->Listings ?? array() ) : ( $container->listings ?? array() ); $fallback = null; foreach ( is_array( $listings ) ? $listings : array() as $listing ) { if ( ! is_object( $listing ) ) { continue; } $availability = $legacy ? ( $listing->Availability->Type ?? '' ) : ( $listing->availability->type ?? '' ); $status = is_string( $availability ) ? strtoupper( str_replace( '_', '', $availability ) ) : ''; if ( in_array( $status, array( 'OUTOFSTOCK', 'UNAVAILABLE', 'DISCONTINUED' ), true ) ) { continue; } $price = $legacy ? ( $listing->Price ?? null ) : ( $listing->price ?? null ); $money = $legacy ? ( $price->Money ?? null ) : ( $price->money ?? null ); $old = $legacy ? ( $price->SavingBasis->Money ?? null ) : ( $price->savingBasis->money ?? null ); $old_currency = Affiai_Offer_Integrity::currency( $legacy ? ( $old->Currency ?? null ) : ( $old->currency ?? null ) ); $restricted = $legacy ? ( $listing->ViolatesMAP ?? false ) : ( $listing->violatesMAP ?? false ); $offer = array( 'offer_state' => 'present', 'availability' => '', 'price' => $restricted ? null : ( $legacy ? ( $money->Amount ?? null ) : ( $money->amount ?? null ) ), 'currency' => $legacy ? ( $money->Currency ?? null ) : ( $money->currency ?? null ), 'discount_price' => $restricted ? null : ( $legacy ? ( $old->Amount ?? null ) : ( $old->amount ?? null ) ) ); if ( ! $old_currency || $old_currency !== Affiai_Offer_Integrity::currency( $offer['currency'] ) ) { $offer['discount_price'] = null; } $offer['discount'] = Affiai_Offer_Integrity::discount( $offer['price'], $offer['discount_price'], $offer['currency'] ); if ( Affiai_Offer_Integrity::money( $offer['price'], $offer['currency'] ) ) { return $offer; } $fallback = $fallback ?? $offer; } return $fallback; } }