0

我正在集成示例代码

我想启用商家私人物品数据,以便我可以传递用户 ID、期间和属性

我无法理解我该怎么做。

我的 googlecheckout 按钮出现在这里,如下所示:

require_once($jconfig->gc_path.'/googlecart.php');
require_once($jconfig->gc_path.'/googleitem.php');
require_once($jconfig->gc_path.'/googleshipping.php');
require_once($jconfig->gc_path.'/googletax.php');

$merchant_id = "SAMPLE";  // Your Merchant ID
$merchant_key = "SAMPLE";  // Your Merchant Key
$server_type = "sandbox";
$currency = "USD";
$cart = new GoogleCart($merchant_id, $merchant_key, $server_type,
$currency); 
$total_count = 1;
$item_1 = new GoogleItem('title',      // Item name
                         'descriptiom', 
                         $price,
                         1); 
$cart->AddItem($item_1);
$cart->SetContinueShoppingUrl($jconfig->response_handler.$generate_url);

// Request buyer's phone number
$cart->SetRequestBuyerPhone(true);  

// Display Google Checkout button
//echo $this->product[0]['welcome_pack']+$this->product[0]['airport_pick_up']+$this->product[0]['airport_drop_off']+$this->product[0]['textbooks']+$totle;
echo $cart->CheckoutButtonCode("SMALL");

我必须在 googlecart.php 中启用它吗?

4

1 回答 1

0

如果您查看源代码,您会看到一个GoogleItem::SetMerchantPrivateItemData,它只是设置GoogleItem::$merchant_private_item_data属性。检查GoogleItem::GetXML揭示GoogleItem::$merchant_private_item_data 可以是一个MerchantPrivate(它似乎没有实现,但你可以编写你自己的,只要它有一个MerchantPrivate::AddMerchantPrivateToXML(gc_XmlBuilder $xml)方法)或一个字符串,它(在 pass through 之后htmlentities)成为merchant-private-item-data元素的内容。如果你想用 XML 构造你的私有数据,你必须实现 class MerchantPrivate

class MerchantPrivate {
    function AddMerchantPrivateToXML(gc_XmlBuilder $xml) {
        $xml->Push('merchant-private-item-data');
        $this->_addMyData($xml);
        $xml->Pop('merchant-private-item-data');            
    }

    abstract protected function _addMyData($xml);
}

class ItemData extends MerchantPrivate {
    public $userid, $period, $attribute;
    function _addMyData(gc_XmlBuilder $xml) {
        $xml->Element('userid', $this->userid);
        $xml->Element('period', $this->period);
        $xml->Element('attribute', $this->attribute);
    }
}
于 2011-06-29T11:33:57.770 回答