首页 \ 问答 \ 从OpenCart中按类别检索产品(Retrieve Products By Category from OpenCart)

从OpenCart中按类别检索产品(Retrieve Products By Category from OpenCart)

如何编写一个PHP代码片段来读取OpenCart数据库以按类别提取产品并将其显示在OpenCart框架之外? 举例来说,我为小部件A和B构建了这个漂亮的前端网站,但是之后安装了一个名为/ cart的子目录,其中安装了OpenCart,并在我的前端网站中加载了某种OpenCart库文件,然后读取数据库以获取产品按类别(A和B)。 或者,也许你知道直接SQL本身的技术?

这个问题不同于这个问题,因为我试图不在OpenCart中构建新模板,而是使用API​​(或直接访问数据库)在OpenCart的应用程序框架之外和我自己的应用程序框架中显示产品。


How do I write a PHP snippet to read an OpenCart database to pull products by category and display it outside of an OpenCart framework? So for instance, I build this nice frontend website for widgets A and B, but then have a subdir called /cart where OpenCart is installed, and in my frontend website I load some kind of OpenCart library file and then read the database to get products by category (A and B). Or, perhaps you know the technique with direct SQL itself?

This question is different than this one because I'm trying to not build a new template in OpenCart, but use an API (or go direct to the database) to show products outside of OpenCart's application framework and in my own application framework.


原文:https://stackoverflow.com/questions/42685929
更新时间:2023-02-25 11:02

最满意答案

你的代码不起作用的原因是因为你的循环是:

for (var i = 0; i <= folderList.Count; i++)

...其中folderListFolder_Settings元素的列表。 只有其中一个,所以你要迭代两次。 你实际上并没有使用folderList[i] ,这是一个很好的工作,因为否则你将在第二次迭代中超出范围。 这样的循环应该总是使用<而不是<=

但是,我强烈建议使用LINQ to XML而不是XmlDocument - 它使一切变得更加简单。 我也建议你尽可能使用foreach循环:

var doc = XDocument.Load("Settings.xml");
foreach (var element in doc.Root.Elements("OtherFolderSettings))
{
    listBox1.Items.Add(element.Value);
}

(哦,并使用语句来干净地关闭资源......)


The reason your code isn't working is because your loop is:

for (var i = 0; i <= folderList.Count; i++)

... where folderList is the list of Folder_Settings elements. There's only one of those, so you're iterating twice. It's a good job you don't actually use folderList[i], because otherwise you'd be out of bounds on the second iteration. Loops like that should pretty much always use < rather than <=.

However, I would strongly recommend using LINQ to XML instead of XmlDocument - it makes everything much simpler. I'd also recommend using foreach loops whenever you can, too:

var doc = XDocument.Load("Settings.xml");
foreach (var element in doc.Root.Elements("OtherFolderSettings))
{
    listBox1.Items.Add(element.Value);
}

(Oh, and use using statements to close resources cleanly...)

相关问答

更多
  • ListBox没有列的概念,所以我想你想在其中显示简单的字符串行。 然后你可以简单地将字符串添加到Items集合中: public PatientList() { InitializeComponent(); HumanResources ListAllPatients = new HumanResources(); List AllPatients = ListAllPatients.PopPatien ...
  • 尝试更改将Destination填充到的查询 Destination = c.Descendants("destination") .Select(e => e.Value) .Where(s => !string.IsNullOrEmpty(s)) .ToList(); 这将使用List填充它,然后您可以将其绑定到您的控件。 Trying changing your query which populates De ...
  • 我会逐步执行您的代码,以确保它循环遍历每个文件。 还要仔细检查并确保将“s”设置为正确的文件。 如果它循环遍历每个文件并成功调用“SetElementValue”,则可能与必须为“foreach”中的每个循环检索“filesToProcess”节点有关。 而不是你拥有的,试试这个: // Now add the elements from the listbox var filesToProcessNode = uElem.Element("filestoProcess"); foreach (string ...
  • 你的问题是列表框没有.recordsource它有一个行来源 Your problem is that a list box does not have a .recordsource It has a RowSource
  • 通过@ fhdrsdg的评论,您将了解如何实现您的结果。您将使用set获取值,然后loop遍历变量unique以插入到Listbox 。 from tkinter import * rows = (('python', 'kivy'), ('python', 'tkinter'),("python","wxpython",32), ('PHP', 'bootstrap'),('html', 'ajax'),('html', 'css') ) root = Tk() l = Listbox(root) ...
  • 每次我做过这个,我都使用RowSource作为列表框,在第一个列表框的OnChange事件中,我构造了一个SQL字符串并更新了第二个列表框的RowSource。 就像是: sSQL = "SELECT * FROM MyTable WHERE MyField = " & forms![HHRRR]![List0].Text & "" Me.Listbox2.RowSource = sSQL Me.Listbox2.Requery 这完全是“空中代码”,可能需要一些调整,但你明白了。 Any time I' ...
  • 你的代码不起作用的原因是因为你的循环是: for (var i = 0; i <= folderList.Count; i++) ...其中folderList是Folder_Settings元素的列表。 只有其中一个,所以你要迭代两次。 你实际上并没有使用folderList[i] ,这是一个很好的工作,因为否则你将在第二次迭代中超出范围。 这样的循环应该总是使用<而不是<= 。 但是,我强烈建议使用LINQ to XML而不是XmlDocument - 它使一切变得更加简单。 我也建议你尽可能使用fo ...
  • var records = from line in File.ReadAllLines(@"D:\file.txt") let parts = line.Split(';') select new { Company = parts[0], Identification = parts[2] }; listBox1.Dat ...
  • 您还必须指定: lstDepartment.DataSource = oCorp.GetEmployeeList(emp); lstDepartment.DataTextField = "EmployeeID"; lstDepartment.DataValueField = "EmployeeID"; lstDepartment.DataBind() You have to also specify this: lstDepartment.DataSour ...
  • 1.如果使用MVVM模式 :在viewModel中实现INotifyPropertyChanged并声明: private ObservableCollection _posts; public ObservableCollection Posts { get{return _posts;} set { _posts = value; RaisePropertyChanged("Posts"); } } 在x ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)