создание продукта в электронной коммерции соната - нет доступных типов объектов - PullRequest
0 голосов
/ 24 мая 2018

У меня проблема с электронной коммерцией Sonata, с созданием Продукта.Я слежу за документацией сонаты и другими постами, связанными с этим, и постоянно получаю сообщение "Нет доступных типов объектов" No object types available

Мои файлы выглядят так:

product.yml

services:
    sonata.ecommerce_demo.product.bowl.manager:
        class: Sonata\ProductBundle\Entity\ProductManager
        arguments:
            - Application\Sonata\ProductBundle\Entity\Bowl
            - @doctrine

    sonata.ecommerce_demo.product.bowl.type:
        class: Application\Sonata\ProductBundle\Provider\BowlProductProvider
        arguments:
            - @serializer

sonata_product.yml

sonata_product:
    products:
        sonata.ecommerce_demo.product.bowl:
            provider: sonata.ecommerce_demo.product.bowl.type
            manager: sonata.ecommerce_demo.product.bowl.manager

Entity.Product.xml

<?xml version="1.0" encoding="UTF-8"?>
<serializer>
    <!-- This file has been generated by the SonataEasyExtendsBundle: https://sonata-project.org/bundles/easy-extends -->
    <class name="Application\Sonata\ProductBundle\Entity\Product" exclusion-policy="all" xml-root-name="_product">
        <discriminator-class value="sonata.ecommerce_demo.product.bowl">Application\Sonata\ProductBundle\Entity\Bowl</discriminator-class>
        <property xml-attribute-map="true" name="id" type="integer" expose="true" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search"/>
    </class>
</serializer>

Bowl.php

<?php
/*
 * This file is part of the <name> project.
 *
 * (c) <yourname> <youremail>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Application\Sonata\ProductBundle\Entity;

//use Sonata\ProductBundle\Entity\ProductProduct;

/**
 * This file has been generated by the Sonata product generation command ( https://sonata-project.org/ )
 *
 * References :
 *   working with object : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
 *
 * @author <yourname> <youremail>
 */
class Bowl extends Product
{
    /**
     * @var integer $id
     */
    protected $id;

    /**
     * Get id
     *
     * @return integer $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
}

Product.php

<?php

namespace Application\Sonata\ProductBundle\Entity;

use Sonata\ProductBundle\Entity\BaseProduct as BaseProduct;

/**
 * This file has been generated by the SonataEasyExtendsBundle.
 *
 * @link https://sonata-project.org/easy-extends
 *
 * References:
 * @link http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
 */
/**
* @ORM\DiscriminatorMap({
 *     product" = "Product"
 * })
*/
abstract class Product extends BaseProduct
{
    /**
     * @var int $id
     */
    protected $id;

    /**
     * Get id.
     *
     * @return int $id
     */
    public function getId()
    {
        return $this->id;
    }
}

composer.json

"require": {
        "php": ">=5.3.9",
        "cocur/slugify": "^2.5",
        "doctrine/doctrine-bundle": "~1.4",
        "doctrine/orm": "^2.4.8",
        "enqueue/amqp-lib": "^0.8.23",
        "friendsofsymfony/rest-bundle": "^2.3",
        "friendsofsymfony/user-bundle": "~1.3",
        "incenteev/composer-parameter-handler": "~2.0",
        "jms/serializer-bundle": "^1.5",
        "kriswallsmith/buzz": "^0.15",
        "liip/monitor-bundle": "^2.6",
        "nelmio/api-doc-bundle": "~2.0",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "sonata-project/admin-bundle": "3.x-dev",
        "sonata-project/block-bundle": "^3.12",
        "sonata-project/cache": "^1.0.3",
        "sonata-project/cache-bundle": "^2.4",
        "sonata-project/classification-bundle": "^3.6",
        "sonata-project/core-bundle": "^3.9",
        "sonata-project/dashboard-bundle": "^0.2.0",
        "sonata-project/datagrid-bundle": "^2.3",
        "sonata-project/doctrine-orm-admin-bundle": "3.x-dev",
        "sonata-project/easy-extends-bundle": "^2.5",
        "sonata-project/ecommerce": "dev-master",
        "sonata-project/formatter-bundle": "^3.4",
        "sonata-project/google-authenticator": "^2.1",
        "sonata-project/media-bundle": "^3.12",
        "sonata-project/news-bundle": "^3.4",
        "sonata-project/notification-bundle": "^3.5",
        "sonata-project/page-bundle": "^3.8",
        "sonata-project/seo-bundle": "^2.5",
        "sonata-project/user-bundle": "3.x-dev",
        "symfony/monolog-bundle": "^3.0.2",
        "symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
        "symfony/symfony": "2.8.*",
        "twig/twig": "^1.0||^2.0"
    },

Я также проверяю sonata sandbox на github и не могу найти то, что яотсутствует.

Я использую Symfony 2.8 и PHP 7.2

1 Ответ

0 голосов
/ 08 июня 2018

После долгих исследований я наконец нашел решение.Разработчики электронной коммерции sonata удаляют метод getClass () из ProductAdmin.php.Этот класс доступен только в ветке 1.x, но не в ветвях высшего уровня.

Оригинальный метод getClass () выглядит следующим образом:

/**
 * @return string
 */
public function getClass()
{
    if ($this->hasSubject()) {
        return get_class($this->getSubject());
    } elseif ($class = $this->getProductClass()) {
        return $class;
    }
    return parent::getClass();
}

и вызывает некоторые ошибки, поэтому решениедобавить слегка модифицированный класс, без второго условия.Добавьте это в ProductAdmin.php.

/**
 * @return string
 */
public function getClass()
{
    if ($class = $this->getProductClass()) {
        return $class;
    }

    return parent::getClass();
}

Я нашел решение для sonata ecommerce github .

...