我不是程序员,但是可以在现有代码中添加一些可选的content api属性。到目前为止,即使字段包含数据,输出还是空的。
我已经编辑了调用php文件及其包含的文件。
可选属性为:
color,sizes,multipack,ageGroup,gender,material
文件运行:ProductsSample_orig.php
相关代码:
include_once('/home/xxxx/public_html/xxxx/class.php');
require_once 'BaseSample.php';
private function createExampleProducts($offerIds) {
$products = [];
foreach ($offerIds as $offerId) {
//print_r($offerId);
foreach($offerId as $offer) {
// echo $offer['name'];
//echo $offer['language'];
$products[] = $this->createExampleProduct($offer['name'],$offer['products_id'],$offer['description'],$offer['color'],$offer['sizes'],$offer['multipack'],$offer['ageGroup'],$offer['gender'],$offer['material'],$offer['image_link'],$offer['sellprice'],$offer['team'],$offer['weight'],$offer['gtin'],$offer['country'],$offer['currency'],$offer['language'],$offer['prodlink'],'',$offer['availability'],$offer['categoryname']);
}
}
return $products;
}
private function createExampleProduct($name,$team_id,$description,$color,$sizes,$multipack,$ageGroup,$gender,$material,$image,$priceselling,$brand,$weight,$gtin,$country,$currency,$language,$link,$delivery_cost,$availability,$category) {
// print_r($offerId);
// echo $priceselling;
// echo "gtin for: ".$team_id." is :".$gtin;
$description=htmlentities($description);
$cat=utf8_encode($category);
// echo $name."\n".$team_id."\n".$description."\n".$image."\n".$priceselling."\n".$brand."\n".$weight."\n".$gtin."\n".$country."\n".$currency."\n".$language."\n".$link."\n".$delivery_cost."\n".$availability."\n".$category;
// die;
$timestamp = date("Y-m-d");
$expires =date("c", strtotime('+1 days', strtotime($timestamp)));
$product = new Google_Service_ShoppingContent_Product();
//$offerd=$id['team_id'];
$product->setOfferId($team_id);
//$name=$id['name'];
$product->setTitle($name);
//$desc=$id['description'];
$product->setDescription($description);
$product->setColor($color);
$product->setSizes($sizes);
$product->setMultipack($multipack);
$product->setAgeGroup($ageGroup);
$product->setGender($gender);
$product->setMaterial($material);
$product->setLink($link);
$product->setImageLink($image);
$product->setBrand($brand);
$product->setContentLanguage($language);
$product->setTargetCountry($country);
$product->setChannel(self::CHANNEL);
$product->setAvailability($availability);
$product->setCondition('new');
$product->setGoogleProductCategory($cat);
$product->setexpirationDate($expires);
if(!empty($gtin)){
$product->setGtin($gtin);
}else{
$product->setidentifierExists(FALSE);
}
$price = new Google_Service_ShoppingContent_Price();
$price->setValue($priceselling);
$price->setCurrency($currency);
$product->setPrice($price);
/* $shippingPrice = new Google_Service_ShoppingContent_Price();
$shippingPrice->setValue($delivery_cost);
$shippingPrice->setCurrency($currency);*/
/* $shipping = new Google_Service_ShoppingContent_ProductShipping(); */
// $shipping->setPrice($shippingPrice);
/* $shipping->setCountry($country); */
/* $shipping->setService('Standard shipping'); */
/* $product->setShipping(array($shipping)); */
$shippingWeight =
new Google_Service_ShoppingContent_ProductShippingWeight();
$shippingWeight->setValue($weight);
$shippingWeight->setUnit('grams');
$product->setShippingWeight($shippingWeight);
================================================ =====================
class.php
包括代码:
$dbpro="SELECT DISTINCT'
vp.virtuemart_product_id AS products_id,
vp.colour AS color,
vp.size AS sizes,
vp.multipack AS multipack,
vp.age_group AS ageGroup,
vp.gender AS gender,
vp.material AS material,
================================================ ============
预期结果:
1个产品的日志输出,大小为5cm
Google_Service_ShoppingContent_Product Object
(
...
[sizeSystem] =>
[sizeType] =>
[sizes] =>
should be:
sizes = 5cm
sizeSystem和sizeType是否应具有关联的字段+变量?
我应该补充一点,当运行时,不会产生任何错误消息,而新添加的属性中只会包含任何内容。
谢谢