首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STRANGE...Not能够在自定义页面上获得magento中的购物车项目(仅当客户登录时)

STRANGE...Not能够在自定义页面上获得magento中的购物车项目(仅当客户登录时)
EN

Stack Overflow用户
提问于 2012-12-31 18:53:38
回答 1查看 2.3K关注 0票数 0

这是我用来获取购物车物品及其属性的标准代码,它只在客户未登录时起作用。一旦我使用我的帐户登录,这个脚本就会停止工作,并且不会返回购物车中的物品。此外,购物车项目计数也为0。但只要我关闭浏览器(会话结束..)并且脚本正确地返回了cartitems!很奇怪,我一直没能找出原因。请给我带路,有人吗?

代码语言:javascript
复制
require_once('../app/Mage.php') ;
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));

$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
//$canProceed=0;
echo $productname = $item->getName();   //HERE IS THE COMPLETE CODE:<?php 
ini_set('display_errors',true);
require_once('../app/Mage.php') ;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();


  //Getting buyer's country label

 $bcountry1 =  $_REQUEST['country']; //gets country code

$_countries = Mage::getResourceModel('directory/country_collection')
                                ->loadData()
                                ->toOptionArray(false);

foreach($_countries as $_country){
if ($_country['value']==$bcountry1){$bcountry = $_country['label'];}
}
//Fetching vendor for each product

$config  = Mage::getConfig()->getResourceConnectionConfig("default_setup");

$dbinfo = array("host" => $config->host,
        "user" => $config->username,
        "pass" => $config->password,
        "dbname" => $config->dbname    );

$hostname = $dbinfo["host"];
$user2 = $dbinfo["user"];
$password = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];


$dbhandle = mysql_connect($hostname,$user2,$password) or die("Unable to connect"); 
$selected = mysql_select_db("myart2",$dbhandle);


$Proceed=0;

//Getting all products in the cart
//echo $cart = Mage::getSingleton('checkout/cart')->getItemsCount();
// Secret Sauce - Initializes the Session for the FRONTEND
// Magento uses different sessions for 'frontend' and 'adminhtml'
Mage::getSingleton('core/session', array('name'=>'frontend'));

$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
//$canProceed=0;
$productname = $item->getName();

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',     $item->getSku(), array('manufacturer'));
    $manufacturer =   $product->getResource()->getAttribute('manufacturer')->getFrontEnd()->getValue($product);


 $qry="select * from vendors WHERE company_name='$manufacturer'";
$result =  mysql_query($qry) or die("Unable to run select query");
  $row = mysql_fetch_array($result) or die("Unable to fetch data");

if( strcasecmp($row['country'],$bcountry)!=0 && $row['ships_abroad']!=1)
{$Proceed=1;$productnames[]=$productname;}
}

if($Proceed==1)
{
echo implode(',',$productnames);
}
else {echo 1; }
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-01 00:38:04

我已经测试了以下四种主要的排列,代码在所有情况下都可以在常用的CE1.7实例中运行:

  • 创建客户报价
  • 通过login
  • Instantiate将客户报价转换为客户报价通过登录
  • 将客户报价与客户报价通过登录

合并

如下所示调整服务器和应用程序环境参数,以查看并排除任何错误(编辑-添加了完整的脚本;注意关闭的"}")

代码语言:javascript
复制
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',true);
require_once('../app/Mage.php') ;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();

$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();

foreach ($items as $item) {
    //$canProceed=0;
    echo $productname = $item->getName();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14100626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档