src/Flowcode/ShopBundle/Controller/AdminProductController.php
public function copyAction(Product $product)
    {


        $productCopy = new Product();
        $copyName = $this->get('translator')->trans('Copy of') . " " . $product->getName();
        $productCopy->setName($copyName);

        $productCopy->setCostPrice($product->getCostPrice());
        $productCopy->setDescription($product->getDescription()??$copyName);
        $productCopy->setCode($product->getCode());
        $productCopy->setImage($product->getImage());
        $productCopy->setPlace($product->getPlace());
        $productCopy->setSalePrice($product->getSalePrice());
        $productCopy->setSupplier($product->getSupplier());
        $productCopy->setWarehouse($product->getWarehouse());

        // boleans
        $productCopy->setEnabled($product->getEnabled());
        $productCopy->setForSale($product->getForSale());
        $productCopy->setCompositionOnDemand($product->isCompositionOnDemand());
        $productCopy->setPack($product->isPack());
        $productCopy->setManualPackPricing($product->isManualPackPricing());
        $productCopy->setRawMaterial($product->getRawMaterial());

        $em = $this->getDoctrine()->getManager();
        $em->persist($productCopy);

        // relations

        /* @var ProductRawMaterial $rawMaterial */
        foreach ($product->getRawMaterials() as $rawMaterial) {
            $rawMaterialCopy = new ProductRawMaterial();
            $rawMaterialCopy->setRawMaterial($rawMaterial->getRawMaterial());
            $rawMaterialCopy->setProduct($productCopy);
            $rawMaterialCopy->setMeasureUnit($rawMaterial->getMeasureUnit());
            $rawMaterialCopy->setQuantity($rawMaterial->getQuantity());

            $em->persist($rawMaterialCopy);

            $productCopy->addRawMaterial($rawMaterialCopy);

        }

        /* @var ProductCategory $category */
        foreach ($product->getCategories() as $category) {
            $productCopy->addCategory($category);
        }

        /* @var ProductCustomField $customField */
        foreach ($product->getCustomFields() as $customField) {
            $customFieldCopy = new ProductCustomField();
            $customFieldCopy->setProduct($productCopy);
            $customFieldCopy->setSettingField($customField->getSettingField());
            $customFieldCopy->setValue($customField->getValue());

            $em->persist($customFieldCopy);

            $productCopy->addCustomField($customFieldCopy);
        }

        $em->flush();


        return $this->redirect($this->generateUrl('product_show', array("id" => $productCopy->getId())));
    }
public function copyAction(Product $product)
    {


        $productCopy = new Product();
        $copyName = $this->get('translator')->trans('Copy of') . " " . $product->getName();
        $productCopy->setName($copyName);

        $productCopy->setCostPrice($product->getCostPrice());
        $productCopy->setDescription($product->getDescription()??$copyName);
        $productCopy->setCode($product->getCode());
        $productCopy->setImage($product->getImage());
        $productCopy->setPlace($product->getPlace());
        $productCopy->setSalePrice($product->getSalePrice());
        $productCopy->setSupplier($product->getSupplier());
        $productCopy->setWarehouse($product->getWarehouse());

        // boleans
        $productCopy->setEnabled($product->getEnabled());
        $productCopy->setForSale($product->getForSale());
        $productCopy->setCompositionOnDemand($product->isCompositionOnDemand());
        $productCopy->setPack($product->isPack());
        $productCopy->setManualPackPricing($product->isManualPackPricing());
        $productCopy->setRawMaterial($product->getRawMaterial());

        $em = $this->getDoctrine()->getManager();
        $em->persist($productCopy);

        // relations

        /* @var ProductRawMaterial $rawMaterial */
        foreach ($product->getRawMaterials() as $rawMaterial) {
            $rawMaterialCopy = new ProductRawMaterial();
            $rawMaterialCopy->setRawMaterial($rawMaterial->getRawMaterial());
            $rawMaterialCopy->setProduct($productCopy);
            $rawMaterialCopy->setMeasureUnit($rawMaterial->getMeasureUnit());
            $rawMaterialCopy->setQuantity($rawMaterial->getQuantity());

            $em->persist($rawMaterialCopy);

            $productCopy->addRawMaterial($rawMaterialCopy);

        }

        /* @var ProductCategory $category */
        foreach ($product->getCategories() as $category) {
            $productCopy->addCategory($category);
        }

        /* @var ProductCustomField $customField */
        foreach ($product->getCustomFields() as $customField) {
            $customFieldCopy = new ProductCustomField();
            $customFieldCopy->setProduct($productCopy);
            $customFieldCopy->setSettingField($customField->getSettingField());
            $customFieldCopy->setValue($customField->getValue());

            $em->persist($customFieldCopy);

            $productCopy->addCustomField($customFieldCopy);
        }

        $em->flush();


        return $this->redirect($this->generateUrl('product_show', array("id" => $productCopy->getId())));
    }
public function copyAction ( Product $ product ) { $ productCopy = new Product ( ) ; $ copyName = $ this -> get ( 'translator' ) -> trans ( 'Copy of' ) . " " . $ product -> getName ( ) ; $ productCopy -> setName ( $ copyName ) ; $ productCopy -> setCostPrice ( $ product -> getCostPrice ( ) ) ; $ productCopy -> setDescription ( $ product -> getDescription ( ) ?? $ copyName ) ; $ productCopy -> setCode ( $ product -> getCode ( ) ) ; $ productCopy -> setImage ( $ product -> getImage ( ) ) ; $ productCopy -> setPlace ( $ product -> getPlace ( ) ) ; $ productCopy -> setSalePrice ( $ product -> getSalePrice ( ) ) ; $ productCopy -> setSupplier ( $ product -> getSupplier ( ) ) ; $ productCopy -> setWarehouse ( $ product -> getWarehouse ( ) ) ; // boleans $ productCopy -> setEnabled ( $ product -> getEnabled ( ) ) ; $ productCopy -> setForSale ( $ product -> getForSale ( ) ) ; $ productCopy -> setCompositionOnDemand ( $ product -> isCompositionOnDemand ( ) ) ; $ productCopy -> setPack ( $ product -> isPack ( ) ) ; $ productCopy -> setManualPackPricing ( $ product -> isManualPackPricing ( ) ) ; $ productCopy -> setRawMaterial ( $ product -> getRawMaterial ( ) ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ productCopy ) ; // relations /* @var ProductRawMaterial $rawMaterial */ foreach ( $ product -> getRawMaterials ( ) as $ rawMaterial ) { $ rawMaterialCopy = new ProductRawMaterial ( ) ; $ rawMaterialCopy -> setRawMaterial ( $ rawMaterial -> getRawMaterial ( ) ) ; $ rawMaterialCopy -> setProduct ( $ productCopy ) ; $ rawMaterialCopy -> setMeasureUnit ( $ rawMaterial -> getMeasureUnit ( ) ) ; $ rawMaterialCopy -> setQuantity ( $ rawMaterial -> getQuantity ( ) ) ; $ em -> persist ( $ rawMaterialCopy ) ; $ productCopy -> addRawMaterial ( $ rawMaterialCopy ) ; } /* @var ProductCategory $category */ foreach ( $ product -> getCategories ( ) as $ category ) { $ productCopy -> addCategory ( $ category ) ; } /* @var ProductCustomField $customField */ foreach ( $ product -> getCustomFields ( ) as $ customField ) { $ customFieldCopy = new ProductCustomField ( ) ; $ customFieldCopy -> setProduct ( $ productCopy ) ; $ customFieldCopy -> setSettingField ( $ customField -> getSettingField ( ) ) ; $ customFieldCopy -> setValue ( $ customField -> getValue ( ) ) ; $ em -> persist ( $ customFieldCopy ) ; $ productCopy -> addCustomField ( $ customFieldCopy ) ; } $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'product_show' , array ( "id" => $ productCopy -> getId ( ) ) ) ) ; }
Displays a form to edit an existing CampaignMail entity.

@Route("/{id}/copy", name="product_copy", requirements={"id"="\d+"})
@Method("GET")
@Template()
Displays a form to edit an existing CampaignMail entity .