0

I know there is a lot of questions like that but i stil couldn't solve my problem after reading them.

Entity

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Orders
 *
 * @ORM\Table(name="orders")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\OrdersRepository")
 */
class Orders
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="shopOrderId", type="string", unique=true)
     */
    private $shopOrderId;
    /**
     * @var string
     *
     * @ORM\Column(name="postBuyFormMsg", type="string")
     */
    private $postBuyFormMsg;

    /**
     * @var boolean
     *
     * @ORM\Column(name="invoice", type="boolean")
     */
    private $invoice;

    /**
     * @var string
     *
     * @ORM\Column(name="payType", type="string")
     */
    private $payType;

    /**
     * @var string
     *
     * @ORM\Column(name="payStatus", type="string")
     */
    private $payStatus;
    /**
     * @var integer
     *
     * @ORM\Column(name="shipmentType", type="integer")
     */
    private $shipmentType;

    /**
     * @var datetime
     *
     * @ORM\Column(name="orderDate", type="datetime")
     */
    private $orderDate;
//    /**
//     * @var integer
//     *
//     * @ORM\Column(name="status", type="integer")
//     */
//    private $status;
    /**
     * @var boolean
     *
     * @ORM\Column(name="verified", type="boolean")
     */
    private $verified = 0;
    /**
     * @var boolean
     *
     * @ORM\Column(name="sent", type="boolean")
     */
    private $sent = 0;
    /**
     * @var boolean
     *
     * @ORM\Column(name="canceled", type="boolean")
     */
    private $canceled = 0;
    /**
     * @var string
     *
     * @ORM\Column(name="adminComment", type="string", nullable=true)
     */
    private $adminComment;
    /**
     * @ORM\ManyToOne(targetEntity="Customer", inversedBy="id")
     * @ORM\JoinColumn(name="customerId", referencedColumnName="id")
     */
    private $customerId;


    /**
     * @ORM\OneToMany(targetEntity="OrdersDetails", mappedBy="orderId")
     */
    private $orderId;
    /**
     * @ORM\OneToMany(targetEntity="OrderData", mappedBy="orderData")
     */
    private $orderData;
    /**
     * @ORM\OneToMany(targetEntity="OrderHistory", mappedBy="orderHistory")
     */
    private $orderHistory;

    /**
     * @ORM\ManyToOne(targetEntity="Shops", inversedBy="id")
     * @ORM\JoinColumn(name="shopId", referencedColumnName="id")
     */
    private $shopId;


    /**
     * Constructor
     */
    public function __construct()
    {
        $this->orderId = new \Doctrine\Common\Collections\ArrayCollection();
        $this->orderData = new \Doctrine\Common\Collections\ArrayCollection();
        $this->orderHistory = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set shopOrderId
     *
     * @param string $shopOrderId
     *
     * @return Orders
     */
    public function setShopOrderId($shopOrderId)
    {
        $this->shopOrderId = $shopOrderId;

        return $this;
    }

    /**
     * Get shopOrderId
     *
     * @return string
     */
    public function getShopOrderId()
    {
        return $this->shopOrderId;
    }

    /**
     * Set postBuyFormMsg
     *
     * @param string $postBuyFormMsg
     *
     * @return Orders
     */
    public function setPostBuyFormMsg($postBuyFormMsg)
    {
        $this->postBuyFormMsg = $postBuyFormMsg;

        return $this;
    }

    /**
     * Get postBuyFormMsg
     *
     * @return string
     */
    public function getPostBuyFormMsg()
    {
        return $this->postBuyFormMsg;
    }

    /**
     * Set invoice
     *
     * @param boolean $invoice
     *
     * @return Orders
     */
    public function setInvoice($invoice)
    {
        $this->invoice = $invoice;

        return $this;
    }

    /**
     * Get invoice
     *
     * @return boolean
     */
    public function getInvoice()
    {
        return $this->invoice;
    }

    /**
     * Set payType
     *
     * @param string $payType
     *
     * @return Orders
     */
    public function setPayType($payType)
    {
        $this->payType = $payType;

        return $this;
    }

    /**
     * Get payType
     *
     * @return string
     */
    public function getPayType()
    {
        return $this->payType;
    }

    /**
     * Set payStatus
     *
     * @param string $payStatus
     *
     * @return Orders
     */
    public function setPayStatus($payStatus)
    {
        $this->payStatus = $payStatus;

        return $this;
    }

    /**
     * Get payStatus
     *
     * @return string
     */
    public function getPayStatus()
    {
        return $this->payStatus;
    }

    /**
     * Set shipmentType
     *
     * @param integer $shipmentType
     *
     * @return Orders
     */
    public function setShipmentType($shipmentType)
    {
        $this->shipmentType = $shipmentType;

        return $this;
    }

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

    /**
     * Set orderDate
     *
     * @param \DateTime $orderDate
     *
     * @return Orders
     */
    public function setOrderDate($orderDate)
    {
        $this->orderDate = $orderDate;

        return $this;
    }

    /**
     * Get orderDate
     *
     * @return \DateTime
     */
    public function getOrderDate()
    {
        return $this->orderDate;
    }

    /**
     * Set verified
     *
     * @param boolean $verified
     *
     * @return Orders
     */
    public function setVerified($verified)
    {
        $this->verified = $verified;

        return $this;
    }

    /**
     * Get verified
     *
     * @return boolean
     */
    public function getVerified()
    {
        return $this->verified;
    }

    /**
     * Set sent
     *
     * @param boolean $sent
     *
     * @return Orders
     */
    public function setSent($sent)
    {
        $this->sent = $sent;

        return $this;
    }

    /**
     * Get sent
     *
     * @return boolean
     */
    public function getSent()
    {
        return $this->sent;
    }

    /**
     * Set canceled
     *
     * @param boolean $canceled
     *
     * @return Orders
     */
    public function setCanceled($canceled)
    {
        $this->canceled = $canceled;

        return $this;
    }

    /**
     * Get canceled
     *
     * @return boolean
     */
    public function getCanceled()
    {
        return $this->canceled;
    }

    /**
     * Set adminComment
     *
     * @param string $adminComment
     *
     * @return Orders
     */
    public function setAdminComment($adminComment)
    {
        $this->adminComment = $adminComment;

        return $this;
    }

    /**
     * Get adminComment
     *
     * @return string
     */
    public function getAdminComment()
    {
        return $this->adminComment;
    }

    /**
     * Set customerId
     *
     * @param \AppBundle\Entity\Customer $customerId
     *
     * @return Orders
     */
    public function setCustomerId(\AppBundle\Entity\Customer $customerId = null)
    {
        $this->customerId = $customerId;

        return $this;
    }

    /**
     * Get customerId
     *
     * @return \AppBundle\Entity\Customer
     */
    public function getCustomerId()
    {
        return $this->customerId;
    }

    /**
     * Add orderId
     *
     * @param \AppBundle\Entity\OrdersDetails $orderId
     *
     * @return Orders
     */
    public function addOrderId(\AppBundle\Entity\OrdersDetails $orderId)
    {
        $this->orderId[] = $orderId;

        return $this;
    }

    /**
     * Remove orderId
     *
     * @param \AppBundle\Entity\OrdersDetails $orderId
     */
    public function removeOrderId(\AppBundle\Entity\OrdersDetails $orderId)
    {
        $this->orderId->removeElement($orderId);
    }

    /**
     * Get orderId
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderId()
    {
        return $this->orderId;
    }

    /**
     * Add orderDatum
     *
     * @param \AppBundle\Entity\OrderData $orderDatum
     *
     * @return Orders
     */
    public function addOrderDatum(\AppBundle\Entity\OrderData $orderDatum)
    {
        $this->orderData[] = $orderDatum;

        return $this;
    }

    /**
     * Remove orderDatum
     *
     * @param \AppBundle\Entity\OrderData $orderDatum
     */
    public function removeOrderDatum(\AppBundle\Entity\OrderData $orderDatum)
    {
        $this->orderData->removeElement($orderDatum);
    }

    /**
     * Get orderData
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderData()
    {
        return $this->orderData;
    }

    /**
     * Add orderHistory
     *
     * @param \AppBundle\Entity\OrderHistory $orderHistory
     *
     * @return Orders
     */
    public function addOrderHistory(\AppBundle\Entity\OrderHistory $orderHistory)
    {
        $this->orderHistory[] = $orderHistory;

        return $this;
    }

    /**
     * Remove orderHistory
     *
     * @param \AppBundle\Entity\OrderHistory $orderHistory
     */
    public function removeOrderHistory(\AppBundle\Entity\OrderHistory $orderHistory)
    {
        $this->orderHistory->removeElement($orderHistory);
    }

    /**
     * Get orderHistory
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrderHistory()
    {
        return $this->orderHistory;
    }

    /**
     * Set shopId
     *
     * @param \AppBundle\Entity\Shops $shopId
     *
     * @return Orders
     */
    public function setShopId(\AppBundle\Entity\Shops $shopId = null)
    {
        $this->shopId = $shopId;

        return $this;
    }

    /**
     * Get shopId
     *
     * @return \AppBundle\Entity\Shops
     */
    public function getShopId()
    {
        return $this->shopId;
    }
}

Controller

public function orderAction(Request $request, $id)
{
    $em = $this->getDoctrine()->getManager();
    $order = $em->getRepository('AppBundle:Orders')->findOneBy(array('id' => $id));
    $adminCommentForm = $this->createForm(adminCommentType::class, $order);

    if ($adminCommentForm->isValid() && $adminCommentForm->isSubmitted()) {
        $order->setAdminComment($adminCommentForm);
        $em->persist($order);
        $em->flush();
    }

    return $this->render(':Orders:order.html.twig',
        array(

            'adminCommentForm' => $adminCommentForm->createView(),

        )
    );
}

FormType

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class adminCommentType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('adminComment',TextareaType::class,array('label'=>false))
            ->add('save', SubmitType::class, array('label' => 'Dodaj'));

    }

    public function configureOptions(OptionsResolver $resolver)
    {

    }

    public function getName()
    {
        return 'app_bundleadmin_comment_type';
    }
}

I tried to add __toString function to my entitylike described here symfony2 Catchable Fatal Error: Object of class could not be converted to string but it doesn't work too. How to return multiple variables with __toString method and finnally get it to work?

2
  • 1
    You left out the handleRequest call or was that a copy/paste error? More importantly, why are you trying to pass the admin comment for to your entity? And why pass an order to a comment form? Try removing $order->setAdminComment($adminCommentForm); completely. handleRequest will set the value. Commented Nov 23, 2016 at 14:04
  • handleRequest call was copy/pase error. I don't know what was i thinking yesterday, after removing all that $order->setAdminComment($adminCommentForm); line, form work perfectly. Thanks!!! Commented Nov 24, 2016 at 8:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.