public function testDeleteError() { $creds = Credentials::get(); // Create a client for our merchant and log in $client = new GSC_Client($creds["merchantId"]); $client->login($creds["email"], $creds["password"]); $product = new GSC_Product(); $type = "application/atom+xml"; $bogusId = "BOGUS_ID_123456789"; $link = $client->getProductUri($bogusId, "US", "en"); $product->setEditLink($link, $type); try { $client->deleteProduct($product); } catch (Exception $e) { $this->assertEquals('Delete request failed.', $e->getMessage()); } }
public function update($editLink = false, $sku = false, $title = false, $description = false, $link = false, $image = false, $price = false, $adult = 'false', $stock = 'in stock') { $product = new GSC_Product(); $type = "application/atom+xml"; try { $product->setContentLanguage('PT-BR'); $product->setTargetCountry('BR'); $product->setSKU($sku); $product->setProductLink($link); $product->setTitle($title); if ($description) { $product->setDescription($description); } $product->setImageLink($image); $product->setBrand(0); $product->setMpn($sku); $product->setPrice($price, "BRL"); $product->setAdult($adult); $product->setAvailability($stock); $product->setCondition("new"); $product->setEditLink($editLink, $type); $this->_client->updateProduct($product); } catch (Exception $e) { $teste = array($sku, $title, $description, $link, $image, $price, $adult, $stock); var_dump($teste); exit; } }
/** * Delete a product. * * @param GSC_Product $product The product to delete. * Must have rel='edit' set. * @param boolean $warnings A boolean to determine if the warnings should be * included. Defaults to false. * @param boolean $dryRun A boolean to determine if the dry-run should be * included. Defaults to false. * @throws GSC_ClientError if the response code is not 200. * @return void */ public function deleteProduct($product, $warnings = false, $dryRun = false) { $productUri = $this->appendQueryParams($product->getEditLink(), $warnings, $dryRun); $this->deleteFromLink($productUri); }
/** * Build a mock product. * * @param string $id The mock product id. * @param string $country The mock product country. * @param string $language The mock product language. * @return GSC_Product The mock product we built. * @author dhermes@google.com **/ function buildMockProduct($id, $country, $language) { $product = new GSC_Product(); $product->setSKU($id); $product->setTargetCountry($country); $product->setContentLanguage($language); $product->setCondition("new"); $title = "Noname XX500-42P Ethernet Switch - 42 Port - 10/100/1000 Base-T"; $product->setTitle($title); $product->setProductLink("http://www.example.com/sku123"); $product->setPrice("25", "usd"); $product->setDescription("42 Port - 10/100/1000 Base-T, very fast."); $gpc = "Electronics > Networking > Hubs & Switches"; $product->setGoogleProductCategory($gpc); $product->setAvailability("in stock"); $shippingService = "Speedy Shipping - Ground"; $product->addShipping("US", "MA", "5.95", "USD", $shippingService); $product->addTax("US", "CA", "8.25", "true"); return $product; }
* under the License. * * @version 1.3 * @author afshar@google.com * @copyright Google Inc, 2011 * @package GShoppingContent */ // import our library require_once 'GShoppingContent.php'; // Get the user credentials $creds = Credentials::get(); // Create a client for our merchant and log in $client = new GSC_Client($creds["merchantId"]); $client->login($creds["email"], $creds["password"]); // Now enter some product data $product = new GSC_Product(); $product->setSKU("dd192"); $product->setProductLink("http://code.google.com/"); $product->setTitle("Dijji Digital Camera"); $product->setPrice("199.99", "usd"); $product->setAdult("false"); $product->setCondition("new"); $product->setBatchOperation("insert"); $batch = new GSC_ProductList(); $batch->addEntry($product); // Finally send the data to the API $feed = $client->batch($batch); $products = $feed->getProducts(); $operation = $products[0]; echo 'Inserted: ' . $operation->getTitle() . "\n"; echo 'Status: ' . $operation->getBatchStatus() . "\n";
* under the License. * * @version 1.3 * @author afshar@google.com, dhermes@google.com * @copyright Google Inc, 2011 * @package GShoppingContent */ // import our library require_once 'GShoppingContent.php'; // Get the user credentials $creds = Credentials::get(); // Create a client for our merchant and log in $client = new GSC_Client($creds["merchantId"]); $client->login($creds["email"], $creds["password"]); // Now enter some product data $product = new GSC_Product(); $product->setSKU("dd192"); $product->setProductLink("http://code.google.com/"); $product->setTitle("Dijji Digital Camera"); $product->setPrice("199.99", "usd"); $product->setAdult("false"); $product->setCondition("new"); // Finally send the data to the API $entry = $client->insertProduct($product); echo 'Inserted: ' . $entry->getTitle() . "\n"; /** * Credentials - Enter your own values * * @author afshar@google.com **/ class Credentials
require_once 'GShoppingContent.php'; require_once 'BuildMockProduct.php'; // Get the user credentials $creds = Credentials::get(); // Create a client for our merchant and log in $client = new GSC_Client($creds["merchantId"]); $client->login($creds["email"], $creds["password"]); // Insert a product so we can delete it $id = "SKU124"; $country = "US"; $language = "en"; $product = buildMockProduct($id, $country, $language); $product = $client->insertProduct($product); echo 'Inserted: ' . $product->getTitle() . "\n"; // Create a dummy <atom:entry> element to include as a batch delete $dummyDeleteEntry = new GSC_Product(); $dummyDeleteEntry->setBatchOperation("delete"); // set the atom id element as specified by the batch protocol $editLink = $client->getProductUri($id, $country, $language); $dummyDeleteEntry->setAtomId($editLink); $batch = new GSC_ProductList(); $batch->addEntry($dummyDeleteEntry); // Finally send the data to the API $feed = $client->batch($batch); $products = $feed->getProducts(); $operation = $products[0]; echo 'Deleted: ' . $operation->getTitle() . "\n"; echo 'Status: ' . $operation->getBatchStatus() . "\n"; /** * Credentials - Enter your own values *