/** * refreshProductSupplierCombinationFormAction * * @param int $idProduct * @param int|string $supplierIds The suppliers ids separate by "-" * * @return string|Response */ public function refreshProductSupplierCombinationFormAction($idProduct, $supplierIds) { $adminProductWrapper = $this->container->get('prestashop.adapter.admin.wrapper.product'); $productAdapter = $this->container->get('prestashop.adapter.data_provider.product'); $response = new Response(); //get product $product = $productAdapter->getProduct((int) $idProduct); $suppliers = explode('-', $supplierIds); if ($supplierIds == 0 || count($suppliers) == 0) { return $response; } if (!is_object($product) || empty($product->id)) { $response->setStatusCode(400); return $response; } //Pre-save of supplier product, needed for well form generation $_POST['supplier_loaded'] = 1; foreach ($suppliers as $idSupplier) { $_POST['check_supplier_' . $idSupplier] = 1; } $adminProductController = $adminProductWrapper->getInstance(); $adminProductController->processSuppliers($idProduct); $modelMapper = new ProductAdminModelAdapter($product, $this->container->get('prestashop.adapter.legacy.context'), $this->container->get('prestashop.adapter.admin.wrapper.product'), $this->container->get('prestashop.adapter.tools'), $this->container->get('prestashop.adapter.data_provider.product'), $this->container->get('prestashop.adapter.data_provider.supplier'), $this->container->get('prestashop.adapter.data_provider.warehouse'), $this->container->get('prestashop.adapter.data_provider.feature'), $this->container->get('prestashop.adapter.data_provider.pack'), $this->container->get('prestashop.adapter.shop.context')); $allFormData = $modelMapper->getFormData(); $form = $this->createFormBuilder($allFormData); $simpleSubForm = $form->create('step6', 'form'); foreach ($suppliers as $idSupplier) { if ($idSupplier == 0 || !is_numeric($idSupplier)) { continue; } $simpleSubForm->add('supplier_combination_' . $idSupplier, 'Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType', array('entry_type' => 'PrestaShopBundle\\Form\\Admin\\Product\\ProductSupplierCombination', 'entry_options' => array('id_supplier' => $idSupplier), 'prototype' => true, 'allow_add' => true, 'required' => false, 'label' => $this->container->get('prestashop.adapter.data_provider.supplier')->getNameById($idSupplier))); } $form->add($simpleSubForm); return $this->render('PrestaShopBundle:Admin:Product/Include/form-supplier-combination.html.twig', array('suppliers' => $suppliers, 'form' => $form->getForm()['step6']->createView())); }
/** * get All Combinations for a product * * @param int $idProduct The product id * * @return string Json */ public function getProductCombinationsAction($idProduct) { $response = new JsonResponse(); //get product $productAdapter = $this->container->get('prestashop.adapter.data_provider.product'); $product = $productAdapter->getProduct((int) $idProduct); //get combinations $modelMapper = new ProductAdminModelAdapter($product, $this->container->get('prestashop.adapter.legacy.context'), $this->container->get('prestashop.adapter.admin.wrapper.product'), $this->container->get('prestashop.adapter.tools'), $this->container->get('prestashop.adapter.data_provider.product'), $this->container->get('prestashop.adapter.data_provider.supplier'), $this->container->get('prestashop.adapter.data_provider.warehouse'), $this->container->get('prestashop.adapter.data_provider.feature'), $this->container->get('prestashop.adapter.data_provider.pack'), $this->container->get('prestashop.adapter.shop.context')); $combinations = $modelMapper->getAttributesResume(); $combinationList = array(); foreach ($combinations as $combination) { $combinationList[] = ['id' => $combination['id_product_attribute'], 'name' => $combination['attribute_designation']]; } $response->setData($combinationList); return $response; }
/** * Refresh the WarehouseCombination data for the given product ID * * @param int $idProduct * @return string|Response */ public function refreshProductWarehouseCombinationFormAction($idProduct) { $productAdapter = $this->container->get('prestashop.adapter.data_provider.product'); $warehouseAdapter = $this->container->get('prestashop.adapter.data_provider.warehouse'); $response = new Response(); //get product and all warehouses $product = $productAdapter->getProduct((int) $idProduct); if (!is_object($product) || empty($product->id)) { $response->setStatusCode(400); return $response; } $warehouses = $warehouseAdapter->getWarehouses(); $modelMapper = new ProductAdminModelAdapter($product, $this->container->get('prestashop.adapter.legacy.context'), $this->container->get('prestashop.adapter.admin.wrapper.product'), $this->container->get('prestashop.adapter.tools'), $this->container->get('prestashop.adapter.data_provider.product'), $this->container->get('prestashop.adapter.data_provider.supplier'), $this->container->get('prestashop.adapter.data_provider.warehouse'), $this->container->get('prestashop.adapter.data_provider.feature'), $this->container->get('prestashop.adapter.data_provider.pack'), $this->container->get('prestashop.adapter.shop.context')); $allFormData = $modelMapper->getFormData(); $form = $this->createFormBuilder($allFormData); $simpleSubForm = $form->create('step4', 'form'); foreach ($warehouses as $warehouse) { $simpleSubForm->add('warehouse_combination_' . $warehouse['id_warehouse'], 'Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType', array('entry_type' => 'PrestaShopBundle\\Form\\Admin\\Product\\ProductWarehouseCombination', 'entry_options' => array('id_warehouse' => $warehouse['id_warehouse']), 'allow_add' => true, 'required' => false, 'label' => $warehouse['name'])); } $form->add($simpleSubForm); return $this->render('PrestaShopBundle:Admin:Product/Include/form-warehouse-combination.html.twig', array('warehouses' => $warehouses, 'form' => $form->getForm()['step4']->createView())); }
/** * @todo make a twig extension and depends only on the required form to avoid generate all the data */ public function renderFieldAction($productId, $step, $fieldName) { $productAdapter = $this->container->get('prestashop.adapter.data_provider.product'); $product = $productAdapter->getProduct($productId); $modelMapper = new ProductAdminModelAdapter($product, $this->container->get('prestashop.adapter.legacy.context'), $this->container->get('prestashop.adapter.admin.wrapper.product'), $this->container->get('prestashop.adapter.tools'), $productAdapter, $this->container->get('prestashop.adapter.data_provider.supplier'), $this->container->get('prestashop.adapter.data_provider.warehouse'), $this->container->get('prestashop.adapter.data_provider.feature'), $this->container->get('prestashop.adapter.data_provider.pack'), $this->container->get('prestashop.adapter.shop.context')); $form = $this->createFormBuilder($modelMapper->getFormData()); switch ($step) { case 'step1': $form->add('step1', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductInformation'); break; case 'step2': $form->add('step2', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductPrice'); break; case 'step3': $form->add('step3', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductQuantity'); break; case 'step4': $form->add('step4', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductShipping'); break; case 'step5': $form->add('step5', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductSeo'); break; case 'step6': $form->add('step6', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductOptions'); break; case 'default': } return $this->render('PrestaShopBundle:Admin/Common/_partials:_form_field.html.twig', ['form' => $form->getForm()->get($step)->get($fieldName)->createView(), 'formId' => $step . '_' . $fieldName . '_rendered']); }