Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从外部代码获取Magento装运报价/费率列表_Php_Magento_Magento 1.7 - Fatal编程技术网

Php 从外部代码获取Magento装运报价/费率列表

Php 从外部代码获取Magento装运报价/费率列表,php,magento,magento-1.7,Php,Magento,Magento 1.7,我有一些代码放在Magento旁边的文件夹中。我正在拉Mage.php做一些事情。我想能够抓住一些航运报价到我的代码类型。我一直在环顾网络,我正努力用它找到任何合理的地方 有人能告诉我实现这一目标的最有效方法吗 我只有以下信息可用于获取费率: Product ID eg, 123 Quantity eg, 1020 Country Code eg, GB Zip code if needed eg, SY12 6AX 我想得到以下信息: Rate eg, £2.50 Title eg, Roy

我有一些代码放在Magento旁边的文件夹中。我正在拉
Mage.php
做一些事情。我想能够抓住一些航运报价到我的代码类型。我一直在环顾网络,我正努力用它找到任何合理的地方

有人能告诉我实现这一目标的最有效方法吗

我只有以下信息可用于获取费率:

Product ID eg, 123
Quantity eg, 1020
Country Code eg, GB
Zip code if needed eg, SY12 6AX
我想得到以下信息:

Rate eg, £2.50
Title eg, Royal Mail Special Delivery
ID eg, 6
然后,我想用我的代码上的选项填充一个单选列表,以便可以选择它们


非常感谢

对于配送报价,您需要将实际报价作为现有的基本地址数据(国家、地区、邮政编码)填入账单和配送地址,然后您可以询问费率:

$quote()->getShippingAddress()->getGroupedAllShippingRates();

请注意,这也取决于运输方法,并且取决于事实,如果它们甚至允许您在报价已经计算或即将计算时给出费率

好的,我已经开始工作了。这是以编程方式从magento获取装运报价的最后一段代码

该功能将返回特定产品、数量、国家/地区、邮政编码的所有可用运费。代码不包括免费送货,这可以通过删除
if($\u rate->getPrice()>0){…

<?php
require_once("Mage.php");
umask(0);
ini_set('display_errors',true); Mage::setIsDeveloperMode(true);
Mage::app();


function getShippingEstimate($productId,$productQty,$countryId,$postcode ) {

    $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
    $_product = Mage::getModel('catalog/product')->load($productId);

    $_product->getStockItem()->setUseConfigManageStock(false);
    $_product->getStockItem()->setManageStock(false);

    $quote->addProduct($_product, $productQty);
    $quote->getShippingAddress()->setCountryId($countryId)->setPostcode($postcode); 
    $quote->getShippingAddress()->collectTotals();
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->getShippingAddress()->collectShippingRates();

    $_rates = $quote->getShippingAddress()->getShippingRatesCollection();

    $shippingRates = array();
    foreach ($_rates as $_rate):
            if($_rate->getPrice() > 0) {
                $shippingRates[] =  array("Title" => $_rate->getMethodTitle(), "Price" => $_rate->getPrice());
            }
    endforeach;

    return $shippingRates;

}
echo "<pre>";
// product id, quantity, country, postcode
print_r(getShippingEstimate(1098,100,"GB","SY21 7NQ"));
echo "</pre>";


如果您有产品ID,您可以轻松加载连接到产品的任何信息。您的问题是什么?找不到正确的型号,或者您在访问/加载数据时有问题吗?我不确定是否应该使用Mage::getSingleton('checkout/cart')或Mage::getModel('sales/quote'))我已经看到了这两个方面的例子,但没有看到一种传递数量的方式。销售/报价似乎是一种冗长的方式。我也在寻找最有效的方式,因为我有20名销售人员全天向客户提供定制报价。嗨,谢谢你,我找到了这篇文章,它似乎可以帮助我获得基于国家/地区的每种运费的最低金额:我想这就是你所说的。我正在努力弄清楚如何创建报价并使用此报价获取运费,而不知道任何国家/地区以外的客户信息。如果你能给我一个完整的示例,那将是非常棒的。如果不担心,谢谢你的输入!
$results = getShippingEstimate(1098,100000,"GB","SY21 7NQ");
$count = -1;
echo "<select>";
foreach ($results as $result):
$count++;
?>
<option value="<?=$count?>"><?=$result["Title"]." - £".$result["Price"]?></option>
<?php
endforeach;
echo "</select>"