@param CreateProduct $createProduct

@throws \Exception
186044
public function handle(CreateProduct $createProduct)
    {
        $this->products->add(new Product(
            new SKU($createProduct->sku()),
            new Price($createProduct->amount(), $createProduct->currency(), $createProduct->precision()),
            $createProduct->isInStock()
        ));
    }
206356
public function afterCreate()
    {
        //create company
        $company = new Companies();
        $company->name = $this->defaultCompanyName;
        $company->users_id = $this->getId();
        if (!$company->save()) {
            throw new Exception(current($company->getMessages()));
        }

        $this->default_company = $company->getId();

        if (!$this->update()) {
            throw new Exception(current($this->getMessages()));
        }
    }
277331
public function createProductAttribute(
        Attribute $attribute,
        ProductInterface $product,
        AttributeValue $attributeValue
    ) {
        $productAttribute = $this->productAttributeRepository->createNew();
        $productAttribute->setAttribute($attribute);
        $productAttribute->setProduct($product);
        $productAttribute->setAttributeValue($attributeValue);
        $this->entityManager->persist($productAttribute);

        $product->addProductAttribute($productAttribute);

        return $productAttribute;
    }
1325411
protected function addProduct()
    {
        $this->controlAccess('product_add');

        if ($this->product->add($this->getSubmitted())) {
            $this->redirect('admin/content/product', $this->text('Product has been added'), 'success');
        }

        $this->redirect('', $this->text('Product has not been added'), 'warning');
    }
579698
public function addProductAction(Product $product, $quantity, Request $request)
    {
        // Find OrderCollection
        $orderCollection = $this->getCurrentCart();

        $quantity = array_key_exists('quantity', $_POST) ? (int) $_POST['quantity'] : $quantity;

        try
        {
            if ('-' == $request->get('remove'))
            {
                $quantity = -1 * $quantity;
            }

            // Add Product to OrderCollection
            $lineItem = $orderCollection->addProduct($product, $quantity);

            // Persisting cascades to Order and OrderCollection
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($lineItem);
            $em->flush();

            if ($quantity > 0) {
                $notice = 'Added '.$quantity.' '
                    .$product->getUnitForNumber($quantity).' of '
                    .$product->getName().' to your cart';
            } else {
                $quantity = abs($quantity);
                $notice = 'Removed '.$quantity.' '
                    .$product->getUnitForNumber($quantity).' of '
                    .$product->getName().' from your cart';
            }

            // Set flash message
            $this->get('session')->getFlashBag()->add('notice', $notice);

            // Save the OrderCollection to the session
            $this->getRequest()->getSession()->set('cart_id', $orderCollection->getId());
        }
        catch (\Exception $e)
        {
            // could not add Product to cart
        }

        $last_route = $request->get('referer');

        if (in_array($last_route, array('_welcome')))
        {
            return $this->redirect($this->generateUrl($last_route));
        }

        return $this->redirect($this->generateUrl('Profile_product_show', array(
            'product_slug' => $product->getSlug(),
            'slug'         => $product->getSeller()->getSlug(),
        )));
    }
1192423
private function createTable(): void
    {
        $statement = 'CREATE TABLE tests (
                          id INTEGER PRIMARY KEY,
                          command TEXT NOT NULL UNIQUE,
                          file_name TEXT NOT NULL,
                          reserved_by_process_id INTEGER,
                          completed INTEGER DEFAULT 0
                        )';

        if ($this->db->exec($statement) === false) {
            throw new Exception('Error while creating sqlite database table: ' . $this->db->errorCode());
        }
    }
582804
public function postCreate(CreateEvent $event)
    {
        if (in_array(Options::USER_SELF_LOG, $event->getOptions())) {
            $this->userManager->logUser($event->getObject());
        }
    }
1296622
public function create() {
        $migration = $this->getMessages();
        if (!$migration) {
            $this->db()->insert($this->table, array('migration' => get_class($this), 'state' => false));
        } else {
            throw new \Exception('Migration ' .  get_class($this) . ' already created');
        }
    }
1036366
public function createAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, Team::getModuleCode(),
                AccessManager::CREATE)
        ) {
            return $response;
        }

        // Create the Creation Form
        $creationForm = $this->getCreationForm($this->getRequest());

        $con = Propel::getConnection();
        $con->beginTransaction();

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($creationForm, "POST");
            // Get the form field values
            $data = $form->getData();

            $createdObject = $this->getService()->createFromArray($data, $this->getCurrentEditionLocale());


            // Substitute _ID_ in the URL with the ID of the created object
            $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());

            $con->commit();

            // Redirect to the success URL
            return $this->generateRedirect($successUrl);

        } catch (FormValidationException $ex) {
            $con->rollBack();
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            $con->rollBack();
            // Any other error
            $error_msg = $ex->getMessage();
        }
        if (false !== $error_msg) {
            $this->setupFormErrorContext(
                $this->getTranslator()->trans("%obj creation", ['%obj' => static::CONTROLLER_ENTITY_NAME]),
                $error_msg,
                $creationForm,
                $ex
            );

            // At this point, the form has error, and should be redisplayed.
            return $this->getListRenderTemplate();
        }

    }
1168647
public function createAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth(self::CONTROLLER_CHECK_RESOURCE, Dealer::getModuleCode(),
                AccessManager::CREATE)
        ) {
            return $response;
        }

        // Create the Creation Form
        $creationForm = $this->getCreationForm($this->getRequest());

        $con = Propel::getConnection();
        $con->beginTransaction();

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($creationForm, "POST");
            // Get the form field values
            $data = $form->getData();

            if (empty($data["day"])) {
                $dataAM = $this->formatData($data);
                $dataPM = $this->formatData($data, 'PM');

                if ($this->hasNullDate($dataAM) && $this->hasNullDate($dataPM)) {
                    $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                } else {
                    if (!$this->hasNullDate($dataAM)) {
                        $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                    }
                    if (!$this->hasNullDate($dataPM)) {
                        $this->getService()->createFromArray($dataPM, $this->getCurrentEditionLocale());
                    }
                }
            } else {
                foreach ($data["day"] as $day) {
                    $currentData = $data;
                    $currentData["day"] = $day;
                    $dataAM = $this->formatData($currentData);
                    $dataPM = $this->formatData($currentData, 'PM');

                    if ($this->hasNullDate($dataAM) && $this->hasNullDate($dataPM)) {
                        $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                    } else {
                        if (!$this->hasNullDate($dataAM)) {
                            $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                        }
                        if (!$this->hasNullDate($dataPM)) {
                            $this->getService()->createFromArray($dataPM, $this->getCurrentEditionLocale());
                        }
                    }
                }
            }


            // Substitute _ID_ in the URL with the ID of the created object
            $successUrl = $creationForm->getSuccessUrl();

            $con->commit();

            // Redirect to the success URL
            return $this->generateRedirect($successUrl);
        } catch (FormValidationException $ex) {
            $con->rollBack();
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            $con->rollBack();
            // Any other error
            $error_msg = $ex->getMessage();
        }
        if (false !== $error_msg) {
            $this->setupFormErrorContext(
                $this->getTranslator()->trans("%obj creation", ['%obj' => static::CONTROLLER_ENTITY_NAME]),
                $error_msg,
                $creationForm,
                $ex
            );

            // At this point, the form has error, and should be redisplayed.
            return $this->generateErrorRedirect($creationForm);
        }
    }
1273091
public function create()
    {
        $instance = self::createProduct($this);
        $this->setId($instance->getId());
        return $instance;
    }
486155
protected function setProductProductBundle($product_id)
    {
        $this->data_product = $this->product->get($product_id);

        if (empty($this->data_product)) {
            $this->outputHttpStatus(404);
        }

        $this->prepareProductBundle($this->data_product);
    }
754874
public function execute()
    {
        $oModel = Factory::model(static::CONFIG_MODEL_NAME, static::CONFIG_MODEL_PROVIDER);

        /** @var Locale $oLocale */
        $oLocale        = Factory::service('Locale');
        $oDefaultLocale = $oLocale->getDefautLocale();

        $aFieldsDescribed = $oModel->describeFields();
        $aFields          = [];

        foreach ($aFieldsDescribed as $oField) {
            if (!in_array($oField->key, static::CONFIG_IGNORE_FIELDS)) {
                $aFields[] = $oField;
            }
        }

        for ($i = 0; $i < static::CONFIG_NUM_PER_SEED; $i++) {
            try {
                $aData = $this->generate($aFields);
                if (classUses($oModel, Localised::class)) {
                    if (!$oModel->create($aData, false, $oDefaultLocale)) {
                        throw new NailsException('Failed to create item. ' . $oModel->lastError());
                    }
                } elseif (!$oModel->create($aData)) {
                    throw new NailsException('Failed to create item. ' . $oModel->lastError());
                }
            } catch (\Exception $e) {
                echo "\nSEED ERROR: " . $e->getMessage();
            }
        }
    }
469170
private function recordProductViewByLoggedUser($productId, $viewedProduct = null) {
        if (!empty($productId)) {
            if ($this->module->log['maxProducts'] == 0) {

                if (empty($viewedProduct)) {
                    $this->recordProductView($productId);
                }
            }
        }
    }
1057519
public function addProduct($product = array())
    {
        if (!is_array($product)) {
            $this->errorMessage[] = 'PRODUCT: Not a valid product!';
        }
        foreach ($this->productFields as $field) {
            if (array_key_exists($field, $product)) {
                $add[$field] = $this->cleanString($product[$field]);
            } elseif (!array_key_exists($field, $product)) {
                $add[$field] = ' ';
                $this->debugMessage[] = 'Missing product field: ' . $field;
            }
        }
        $this->products[] = $add;
    }
947940
private function creationStacks()
    {
        $cloudFormation = $this->getService();

        if (true !== $this->getUpdateOnConflict()) {
            throw new \BuildException('Stack ' . $this->getName() . ' not exist. Creation stack was skip due to property updateOnConflict set to false');
        }

        try {
            $this->log('Create stacks...');
            $cloudFormation->createStack($this->stackProperties());
        } catch (CloudFormationException $e) {
            if ($e->getAwsErrorCode() !== 'AlreadyExistsException') {
                throw $e;
            } else {
                $this->log('stack [' . $this->getName() . '] creation already in progress.');
            }
        }
    }
1128510
protected function addProductClass()
    {
        if (!$this->isError()) {
            $id = $this->product_class->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }