В: Как добавить поле формы в кассу? - PullRequest
0 голосов
/ 02 мая 2018

Я пытался добавить поле настраиваемой формы на шаг оформления заказа метода доставки, где клиент может выбрать дату доставки.

Я добавил значение delivery_date в Отгрузку, оно отображается в логах дампа и mysql.

Я написал файл ShipmentTypeExtension, как этот

<?php

namespace AppBundle\Form\Extension;

use Sylius\Bundle\ShippingBundle\Form\Type\ShipmentType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use AppBundle\Entity\Shipment;

final class ShipmentTypeExtension extends AbstractTypeExtension
{
    /**
     *  {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('delivery_date', DateType::class, [
           'required' => true,
           'label' => 'delivery_date',
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function getExtendedType(): string
    {
        return ShipmentType::class;
    }
}

Я добавил services.yml в AppBundle / Resources / config

services:
    app.form.extension.type.shipment:
        class: AppBundle\Form\Extension\ShipmentTypeExtension
        tags:
          - { name: form.type_extension, extended_type: Sylius\Bundle\ShippingBundle\Form\Type\ShipmentType }

И добавить эту часть в мой config.yml

sylius_shipping:
    resources:
        shipment:
            classes:
                model: AppBundle\Entity\Shipment

Я переписал _shipment.html.twig и добавил эту строку после цикла for, где он выводит все методы доставки

{% include '@SyliusShop/Checkout/SelectShipping/_deliveryTimePicker.html.twig' %}

Итак, наконец, я могу покопаться в моем новом _deliveryTimePicker.html.twig, чтобы попытаться добавить поле datepicker.

Но это не работает, как правильно отрисовать форму?

Вот мой дамп ветки ():

array:17 [▼
  "configuration" => RequestConfiguration {#25119 ▶}
  "metadata" => Metadata {#4881 ▶}
  "resource" => Order {#15648 ▶}
  "order" => Order {#15648 ▶}
  "form" => FormView {#37012 ▼
    +vars: array:24 [▼
      "value" => Shipment {#35552 ▶}
      "attr" => []
      "form" => FormView {#37012}
      "id" => "sylius_checkout_select_shipping_shipments_0"
      "name" => "0"
      "full_name" => "sylius_checkout_select_shipping[shipments][0]"
      "disabled" => false
      "label" => null
      "label_format" => null
      "multipart" => false
      "block_prefixes" => array:3 [▶]
      "unique_block_prefix" => "_sylius_checkout_select_shipping_shipments_entry"
      "translation_domain" => null
      "cache_key" => "_sylius_checkout_select_shipping_shipments_entry_sylius_checkout_shipment"
      "errors" => FormErrorIterator {#37013 ▶}
      "valid" => true
      "data" => Shipment {#35552 ▶}
      "required" => true
      "size" => null
      "label_attr" => []
      "compound" => true
      "method" => "POST"
      "action" => ""
      "submitted" => false
    ]
    +parent: FormView {#37008 ▶}
    +children: array:1 [▶]
    -rendered: false
    -methodRendered: false
  }
  "wrap_fields_with_addons" => true
  "app" => AppVariable {#23784 ▶}
  "sylius" => ShopperContext_d398ef6 {#4770 ▶}
  "sylius_base_locale" => "de"
  "sylius_meta" => array:1 [▶]
  "sonata_block" => GlobalVariables {#24160 ▶}
  "shipment" => Shipment {#35552 ▼
    #delivery_date: null
    #order: Order {#15648}
    #id: 4
    #state: "cart"
    #method: ShippingMethod {#35915 ▶}
    #units: PersistentCollection {#35916 ▶}
    #tracking: null
    #createdAt: DateTime @1525251156 {#35547 ▶}
    #updatedAt: DateTime @1525251157 {#35548 ▶}
  }
  "_parent" => array:11 [▶]
  "_seq" => PersistentCollection {#17988 ▶}
  "_iterated" => false
  "loop" => array:8 [▶]
  "_key" => 0
]

Это ошибка, которую я получаю:

Neither the property "delivery_date" nor one of the methods "delivery_date()", "getdelivery_date()"/"isdelivery_date()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView"
...