首页 \ 问答 \ Opencart 2.2.0定义库存状态ID(Opencart 2.2.0 define stock status ID)

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 the

Undefined 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.


原文:
更新时间:2022-04-15 07:04

最满意答案

好吧,所以我终于弄明白了这个问题。

首先,我对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('/') ...
  • 您需要清理适配器,然后添加项目并通知。 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 ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • 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)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置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])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)