Opencart 2.2.0定义库存状态ID(Opencart 2.2.0 define stock status ID)
即使我有点尴尬地问这个问题,这里也是。 我试图在我的控制器文件中定义$ stock_status_id变量,我将在后面的tpl中回显。 我在控制器文件中设置为
'stock_status_id' => $result['status_stock_id'],
但它给了我未定义的索引'stock_status_id'错误
。 通常,这就足够了,就像我定义的其他变量一样。 我在这做错了什么? stock_status_id字段存在于oc_product表中。 我的整个控制器文件如下:
<?php class ControllerModuleDobavljivi extends Controller { public function index($setting) { $this->load->language('module/dobavljivi'); $data['logged'] = $this->customer->isLogged(); $data['heading_title'] = $this->language->get('heading_title'); $data['customer_group_id'] = $this->customer->getGroupId(); $data['text_tax'] = $this->language->get('text_tax'); $data['button_cart'] = $this->language->get('button_cart'); $data['button_wishlist'] = $this->language->get('button_wishlist'); $data['button_compare'] = $this->language->get('button_compare'); $this->load->model('catalog/product'); $this->load->model('tool/image'); $data['products'] = array(); $filter_data = array( 'sort' => 'p.stock_status_id', 'order' => 'DESC', 'start' => 0, 'limit' => $setting['limit'] ); $results = $this->model_catalog_product->getProducts($filter_data); if ($results) { foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']); } else { $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']); } if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); $wholesale = $this->currency->format($this->tax->calculate($result['wholesale'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); } else { $price = false; $wholesale = false; } if ((float)$result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); } else { $special = false; } if ($this->config->get('config_tax')) { $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']); } else { $tax = false; } if ($this->config->get('config_review_status')) { $rating = $result['rating']; } else { $rating = false; } $data['products'][] = array( 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'stock_status_id' => $result['status_stock_id'], 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..', 'price' => $price, 'wholesale' => $wholesale, 'special' => $special, 'tax' => $tax, 'upc' => $result['upc'], 'rating' => $rating, 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']) ); } return $this->load->view('module/dobavljivi', $data); } } }
谢谢。
Even though I am somewhat embarrassed to ask this question, here it is. I am trying to define $stock_status_id variable in my controller file which I will echo in my tpl afterwords. I set in controller file as
'stock_status_id' => $result['status_stock_id'],
but it gives me theUndefined index 'stock_status_id' error
. Normally, this would be enough, as it was with other variables I defined. What am i doing wrong here? The stock_status_id field exists in oc_product table. My entire controller file is as following:
<?php class ControllerModuleDobavljivi extends Controller { public function index($setting) { $this->load->language('module/dobavljivi'); $data['logged'] = $this->customer->isLogged(); $data['heading_title'] = $this->language->get('heading_title'); $data['customer_group_id'] = $this->customer->getGroupId(); $data['text_tax'] = $this->language->get('text_tax'); $data['button_cart'] = $this->language->get('button_cart'); $data['button_wishlist'] = $this->language->get('button_wishlist'); $data['button_compare'] = $this->language->get('button_compare'); $this->load->model('catalog/product'); $this->load->model('tool/image'); $data['products'] = array(); $filter_data = array( 'sort' => 'p.stock_status_id', 'order' => 'DESC', 'start' => 0, 'limit' => $setting['limit'] ); $results = $this->model_catalog_product->getProducts($filter_data); if ($results) { foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']); } else { $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']); } if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); $wholesale = $this->currency->format($this->tax->calculate($result['wholesale'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); } else { $price = false; $wholesale = false; } if ((float)$result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); } else { $special = false; } if ($this->config->get('config_tax')) { $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']); } else { $tax = false; } if ($this->config->get('config_review_status')) { $rating = $result['rating']; } else { $rating = false; } $data['products'][] = array( 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'stock_status_id' => $result['status_stock_id'], 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..', 'price' => $price, 'wholesale' => $wholesale, 'special' => $special, 'tax' => $tax, 'upc' => $result['upc'], 'rating' => $rating, 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']) ); } return $this->load->view('module/dobavljivi', $data); } } }
Thanks.
原文:
最满意答案
好吧,所以我终于弄明白了这个问题。
首先,我对
Fragment
是对的:Android不允许你在同一个布局中多次充气。然后,我发现的解决方案比使用
BaseAdapter
。我创建了一个
MyViewPattern
类和一个相关的布局,可以包含在任何地方:适配器或经典布局。 为了补充它(填充它),我刚刚在我的类模式中添加了一个静态方法。 此方法使用提供的参数填充每个元素。如果您有任何其他解决方法,请随时发布!
Alright, so I have finally figured it out this problem.
Firstly, I was right about
Fragment
: Android does not allow you to inflate it multiple times in a same layout.Then, the solution I have found is quite easy and cleaner than using
BaseAdapter
.I created a
MyViewPattern
class and an associated layout, which can be included anywhere: either in an adapter or a classic layout. In order to hydrate it (fill it), I have just added a static method in my class pattern. This method fills out every element using provided arguments.If you have any other workaround, feel free to post them!
相关问答
更多-
请查看以下演示文稿,其中概述了此确切行为: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/04_07_Advanced_adapter_usage_and_mashup.pdf Worklight甚至提供相应的样本来补充演示: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/AdapterMashUpProject. ...
-
这就是我现在正在做的事情。 会喜欢其他解决方案。 DS.Store.reopen({ apiPathFor: function() { var url = arguments.length ? Array.prototype.slice.call(arguments).join('/') : '' , adapter = this.adapterFor('application'); return [adapter.urlPrefix(), url].join('/') ...
-
如何更新适配器?(How to update adapter?)[2023-10-08]
您需要清理适配器,然后添加项目并通知。 adapterSection.clear(); adapterSection.addAll(data); adapterSection.notifyDataSetChanged(); 希望它有所帮助。 You need to clean your adapter, then add items and notify. adapterSection.clear(); adapterSection.addAll(data); adapterSection.notifyD ... -
这是因为不支持从JavaScript适配器调用Java适配器的选项。 您可以将适配器作为端点放在JavaScript的XML - > connectionPolicy中,但通常此流程未经测试且不受支持。 That is because the option to call a Java adapter from a JavaScript adapter is not supported. You could put the adapter as the endpoint in the JavaScript' ...
-
.NET中的Runtime Callable Wrapper(RCW)功能更像是Proxy模式的应用程序,因为.NET类镜像了底层COM组件的接口。 来自Sourcemaking的报价: 适配器为其主题提供不同的界面。 代理提供相同的接口。 相关资源: 运行时可调用包装器(RCW) 代理设计模式 适配器设计模式 The Runtime Callable Wrapper (RCW) functionality in .NET is more an application of the Proxy patter ...
-
在C#中 foreach(var nic in NetworkInterface.GetAllNetworkInterfaces.Where(n => n.OperationalStatus == OperationStatus.UP) { if(nic.GetIsNetworkAvailable()) { //nic is attached to some form of network } } VB .NET ForEach nic in NetworkInter ...
-
设置AbsListView.LayoutParams而不是LinearLayout.LayoutParams 。 LayoutParams将在ViewGroup为子级设置。 由于您的布局是AbsListView的子项, AbsListView您应该设置其布局窗格。 Set AbsListView.LayoutParams instead of LinearLayout.LayoutParams. LayoutParams are to be set for a child in ViewGroup. Sin ...
-
我在这里找到了解决方案: 什么时候应该在片段中获得宽度视图 。 @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.post(new Runnable() { @Override public void run() { // do op ...
-
只因为你可以,并不意味着你应该。 注册适配器是类外的一行代码,所以我只是这样做,而不是将行为隐藏在元类中。 显式优于隐式。 Just because you can, doesn't mean you should. Registering the adapter is a single line of code outside the class, so I would just do that instead of tucking the behaviour in a metaclass. Explic ...
-
好吧,所以我终于弄明白了这个问题。 首先,我对Fragment是对的:Android不允许你在同一个布局中多次充气。 然后,我发现的解决方案比使用BaseAdapter 。 我创建了一个MyViewPattern类和一个相关的布局,可以包含在任何地方:适配器或经典布局。 为了补充它(填充它),我刚刚在我的类模式中添加了一个静态方法。 此方法使用提供的参数填充每个元素。 如果您有任何其他解决方法,请随时发布! Alright, so I have finally figured it out this pro ...