我对magento和PHP相当陌生,所以如果解决方案很明显,请原谅我,但是我在报价项中设置选项然后稍后检索它们时遇到问题。我一直在编写的代码是 restservice 文件夹中的扩展代码,如下所示:
function AddToCart($email, $productId, $quantity, $colour, $size){
$customer = GetCustomer($email);
$product = GetProduct($productId);
$quote = Mage::getModel('sales/quote')->loadByCustomer($customer);
$quote->setStoreId(Mage::app()->getStore()->getId());
$quote->assignCustomer($customer);
$options = array("product_id" => $productId,
"qty" => $quantity,
"options" => array ("colour" => $colour,
"size" => $size));
$optionsParam = new Varien_Object();
$optionsParam->setData($options);
$quote->addProduct($product, $optionsParam);
$quote->collectTotals()->save();
}
以及检索它的代码:
FormatQuoteItems($quote_items){
$results = array();
foreach ($quote_items as $quote_item) {
$id = $quote_item->getId();
$price = $quote_item->getPrice();
$quantity = intval($quote_item->getQty());
$colouroption = $quote_item->getOptionByCode("colour");
$sizeoption = $quote_item->getOptionByCode("size");
$colour = $colouroption->getValue();
$size = $sizeoption->getValue();
$results[$id] = array("Id" => $id,
"ProductId" => $quote_item->getProductId(),
"Name" => $quote_item->getName(),
"Barcode" => $quote_item->getSku(),
"Quantity" => $quantity,
"Price" => $price,
"Total" => $quantity * $price,
"Colour" => $colour,
"Size" => $size);
}
return array_values($results);
}
我已经从论坛上发布的代码片段中尝试了不同的想法,但似乎我想要实现的目标如此简单,以至于我一定错过了一些明显的东西。热烈欢迎任何指示,谢谢。
你能发布你从退货array_values得到的东西吗?看起来直接的对象关系可能存在问题,但需要查看输出。