number ); } $helper = new atkp_offertable_helper(); $message = ''; if ( $shop != null ) { try { $message = $shop->provider->checklogon( $shop ); } catch ( Exception $e ) { $message = 'Shop Exception: ' . $e->getMessage(); } $atresponse = null; if ( $message == '' ) { try { $atresponse = $shop->provider->retrieve_products( $product_ids, $id_type ); } catch ( Exception $e ) { $message = 'Request Exception: ' . $e->getMessage(); } } } foreach ( $offers as $offer ) { $errormessage = ''; if ( $shop != null ) { $responseitem = null; if ( $message == '' && $atresponse->errormessage == '' ) { foreach ( $atresponse->responseitems as $item ) { if ( (string) $offer->number == (string) $item->uniqueid ) { $responseitem = $item; } } } if ( $message != '' ) { $errormessage = 'Shop error: ' . $message; } else if ( $atresponse->errormessage != '' ) { $errormessage = 'Request error: ' . $atresponse->errormessage; } else if ( $responseitem == null ) { $errormessage = 'Product not returned: ' . $offer->number; } else if ( $responseitem->errormessage != '' ) { $errormessage = 'Item error: ' . $responseitem->errormessage; } } $offer->message = $errormessage; $offer->shipping = $responseitem->productitem == null ? '' : $responseitem->productitem->shipping; $offer->shippingfloat = $responseitem->productitem == null ? 0 : $responseitem->productitem->shippingfloat; $offer->availability = $responseitem->productitem == null ? '' : $responseitem->productitem->availability; $offer->price = $responseitem->productitem == null ? '' : $responseitem->productitem->saleprice; $offer->pricefloat = $responseitem->productitem == null ? 0 : $responseitem->productitem->salepricefloat; $offer->link = $responseitem->productitem == null ? '' : $productservice->shorten_url( '', $shop->id, $responseitem->productitem->producturl ); $offer->title = $responseitem->productitem == null ? '' : ATKPTools::clear_string( $responseitem->productitem->title);; $helper->update_offer( $offer ); if(atkp_options::$loader->get_pricehistory_enabled()) { $history = new atkp_pricehistorytable_helper(); $history->create_history_entry($offer->productid, $offer->shopid, $offer->price, $offer->pricefloat); } //Wurde das Produkt bereits exportiert nach der aktualisierung? Flag hier zurücksetzen if($offer->productid != '' && $offer->productid != 0) ATKPTools::set_post_setting( $offer->productid, ATKP_PRODUCT_POSTTYPE . '_isexported', false ); } } /** * Löscht alle Angebote zu einem Produkt (oder Liste) und erstellt leere Einträge für die nächste aktualisierung der Angebote * * @param atkp_product $product Das atkp_product welches zurückgesetzt werden soll * @param string $listid Die Listen-ID in dem das Produkt erscheint (wenn eine Liste) */ public function clear_offers( $product, $listid = '' ) { //wir holen uns alle shops + eans und legen dafür eine offer row an //danach gehen wir die daten pro shop durch... $filterarray = array(); $alloffers = array(); $atkp_offertable_helper = new atkp_offertable_helper(); if ( $listid != '' ) { $product_offers = $atkp_offertable_helper->get_offers_by_listid( $listid, $product->asin ); } else { $product_offers = $atkp_offertable_helper->get_offers_by_productid( $product->productid ); } if ( $product_offers != null && $product_offers != '' ) { foreach ( $product_offers as $offer ) { if ( $offer->type == 2 ) { if ( ! array_key_exists( $offer->shopid, $filterarray ) || ! is_array( $filterarray[ $offer->shopid ] ) ) { $filterarray[ $offer->shopid ] = array(); } array_push( $filterarray[ $offer->shopid ], $offer ); array_push( $alloffers, $offer ); } } } $eans = array(); if ( $product->ean != '' ) { $eansex = explode( ',', $product->ean ); foreach ( $eansex as $ean ) { $ean = trim( $ean ); if ( $ean != '' ) { array_push( $eans, $ean ); } } } //TODO: implement bulk offers check: bulk_offers_supported //aufgrund von unzähligen Shops pro affiliate-netzwerk ist es unmöglich für jeden shop einen request abzusetzen. $shops = atkp_shop::get_list( null, true ); foreach ( $shops as $subshop ) { $enableofferload = $subshop->enablepricecomparison; if ( ! array_key_exists( $subshop->id, $filterarray ) || ! is_array( $filterarray[ $subshop->id ] ) ) { $filterarray[ $subshop->id ] = array(); } if ( $product->shopid != $subshop->id && $enableofferload ) { foreach ( $eans as $ean ) { $offer = new atkp_product_offer(); $offer->id = random_int( 1, 99999 ); $offer->type = 1; $offer->shopid = $subshop->id; $offer->number = $ean; array_push( $filterarray[ $subshop->id ], $offer ); array_push( $alloffers, $offer ); } } } $mergedoffers = array(); //alte einträge übernehmen, falls vorhanden foreach ( $alloffers as $checkoffer ) { $added = false; if ( $product_offers != null && $product_offers != '' ) { foreach ( $product_offers as $offer ) { if ( $checkoffer->number == $offer->number && $checkoffer->shopid == $offer->shopid && $checkoffer->type == $offer->type ) { $offer->updatedon = null; $offer->message = null; $added = true; array_push( $mergedoffers, $offer ); break; } } } if ( ! $added ) { array_push( $mergedoffers, $checkoffer ); } } if ( $listid != '' ) { $atkp_offertable_helper->update_offers_by_listid( $listid, $product->asin, $mergedoffers ); } else { $atkp_offertable_helper->update_offers_by_productid( $product->productid, $mergedoffers ); } } }