Magento 2-在“产品详细信息”选项卡中显示自定义产品属性

时间:2018-09-02 10:54:03

标签: magento2

我已经创建了几个自定义产品属性,如果在Magento Admin中输入了数据,我需要它们显示在“产品详细信息”选项卡上。一共有三个,在很多情况下,这三个都有数据,但大约有20%的产品中有一个或两个都有数据。

我已经很容易地创建了属性,但是我努力使它们显示在前端。我已经粘贴了布局文件的代码和属性的phtml文件。

我得到的结果是空白的产品屏幕,根本没有任何信息。肯定是一个错误,但是经过数小时的观察,我还是很想念它。

下面是自定义catalog_product_view.xml

final   StorageReference fileupload=mStorage.child("Photos").child(uri.getLastPathSegment());
UploadTask uploadTask = fileupload.putFile(file);

Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }
        return ref.getDownloadUrl();

    }
    }).addOnCompleteListener(new OnCompleteListener<Uri>() {
        @Override
        public void onComplete(@NonNull Task<Uri> task) {
            if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
                Picasso.get().load(downloadUri.toString()).into(image);

            } else {
                 // Handle failures
            }
       }
});

下面是在布局文件中调用的product_attributes.phtml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page layout="2columns-right" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="product.info.stock.sku" destination="product.info.price" after="product.price.final"/>
        <move element="page.main.title" destination="product.info.main" before="-"/>
        <referenceBlock name="product.info.overview" remove="true"/>

        <referenceBlock name="product.info.details">

          <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.description." template="Magento_Catalog::product/view/product_attributes.phtml" group="detailed_info">
            <arguments>
              <argument name="at_call" xsi:type="string">getDescription</argument>
              <argument name="at_code" xsi:type="string">description</argument>
              <argument name="css_class" xsi:type="string">description</argument>
              <argument name="at_label" xsi:type="string">none</argument>
              <argument name="title" translate="true" xsi:type="string">Product Details</argument>
            </arguments>
          </block>

          <block class="Magento\Catalog\Block\Product\View" name="deliveryinfo.tab" as="deliveryinfo" template="product/view/delivery_info.phtml" group="detailed_info" >
            <arguments>
              <argument translate="true" name="title" xsi:type="string">Delivery</argument>
            </arguments>
          </block>

        </referenceBlock>

        <referenceContainer name="sidebar.main">
          <block class="Magento\Cms\Block\Block" name="sidebar_delivery" after="-">
            <arguments>
              <argument name="block_id" xsi:type="string">sidebar_delivery</argument>
            </arguments>
          </block>

          <block class="Magento\Cms\Block\Block" name="sidebar_instructions" after="-">
            <arguments>
              <argument name="block_id" xsi:type="string">sidebar_instructions</argument>
            </arguments>
          </block> 

          <block class="Magento\Cms\Block\Block" name="sidebar_brochures" after="-">
            <arguments>
              <argument name="block_id" xsi:type="string">sidebar_brochures</argument>
            </arguments>
          </block>

          <block class="Magento\Cms\Block\Block" name="sidebar_blog" after="-">
            <arguments>
              <argument name="block_id" xsi:type="string">sidebar_blog</argument>
            </arguments>
          </block>
        </referenceContainer> 
    </body>
</page>

这可能是我做错了的可笑的简单事情,但我一生都找不到。

该站点位于Community Edition 2.2.5上,并且服务器正在运行PHP 7.1

任何建议表示赞赏。

Kev

1 个答案:

答案 0 :(得分:0)

最终解决了该问题。我错过了一个结束括号。

此行:

public class Task
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Role> Roles { get; set; }
    public virtual ICollection<Task> ChildTask { get; set; }
    public virtual ICollection<Task> ParentTask { get; set; }
}

public class Role
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Task> Tasks { get; set; }
}

应该是:

if (!empty($dimensions) || !empty($features_benefits) || !empty($flooring_specification) {

我知道那会很简单。现在可以正常工作。