Adds product to cart
@return array|bool|\yii\web\Response
505163
public function actionAdd()
    {
        $model = new CartForm();
        $post = \Yii::$app->request->post();

        if ($model->load(Yii::$app->request->post())) {
            if ($model->validate()) {

                $additionalProductForm = [];
                $productAdditionalProducts = ProductAdditionalProduct::find()->where(['product_id' => $model->productId])
                    ->indexBy('additional_product_id')->all();
                foreach ($productAdditionalProducts as $key => $productAdditionalProduct) {
                    $additionalProductForm[$key] = new AdditionalProductForm();
                }

                if (!empty($productAdditionalProducts)) {
                    Model::loadMultiple($additionalProductForm, $post);
                    Model::validateMultiple($additionalProductForm);
                }

                Module::$cart->add($model->productId, $model->count,
                    json_encode($model->attribute_value_id), $additionalProductForm, $model->combinationId
                );

                if (\Yii::$app->request->isAjax) {
                    $data = [
                        'orderCounterValue' => Module::$cart->getOrderItemsCount(),
                        'totalCost' => \Yii::$app->formatter->asCurrency(Module::$cart->getTotalCost())
                    ];
                    Yii::$app->response->format = Response::FORMAT_JSON;
                    
                    return Json::encode($data);
                }

                Yii::$app->getSession()->setFlash('success',
                    Yii::t('cart', 'You have successfully added this product to cart')
                );
            } else {
                Yii::$app->log->logger->log($model->errors, Logger::LEVEL_ERROR, 'application.shop.product');
                Yii::$app->session->setFlash('error',
                    Yii::t('cart', 'An error occurred while adding a product, please try again later')
                );
            }
        }

        if (\Yii::$app->request->isAjax) {
            return false;
        }

        return $this->redirect(Yii::$app->request->referrer);
    }
543246
public function newAction()
    {
        $entity = new Product();

        $entity = $this->addProductItemFieldData($entity);


        $form = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
1122335
public function getProductsAjax()
    {
        if (!$this->access('product')) {
            return array('error' => $this->text('No access'));
        }

        $params = array(
            'status' => $this->getPosted('status'),
            'title_sku' => $this->getPosted('term'),
            'store_id' => $this->getPosted('store_id'),
            'limit' => array(0, $this->config('autocomplete_limit', 10))
        );

        $products = (array) $this->sku->getList($params);

        $product_ids = array();

        foreach ($products as $product) {
            $product_ids[] = $product['product_id'];
        }

        $options = array(
            'entity' => 'product',
            'entity_id' => $product_ids,
            'template_item' => 'backend|content/product/suggestion'
        );

        foreach ($products as &$product) {
            $this->setItemThumb($product, $this->image, $options);
            $this->setItemPriceFormatted($product, $this->price);
            $this->setItemRendered($product, array('item' => $product), $options);
        }

        return $products;
    }
227535
public function CartForm()
    {
        $fields = new FieldList();

        $actions = new FieldList(
            FormAction::create('doUpdate', _t('Checkout.UpdateCart', 'Update Cart'))
                ->addExtraClass('btn')
                ->addExtraClass('btn-blue btn-info')
        );

        $form = Form::create($this, "CartForm", $fields, $actions)
            ->addExtraClass("forms")
            ->setTemplate("ShoppingCartForm");

        $this->extend("updateCartForm", $form);

        return $form;
    }
384656
private function addProductData($data)
    {
        $product = $data['product'];

        $productData = [
            'title' => $product->getName(),
            'image' => $this->getImageUrl($product),
            'url'   => $product->getProductUrl(),
            'price' => $this->renderProductPrice($product, \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE),
        ];

        foreach ($this->attributes as $attributeCode) {
            if ($product->hasData($attributeCode)) {
                $productData[$attributeCode] = $product->getData($attributeCode);
                if ($product->getResource()->getAttribute($attributeCode)->usesSource()) {
                    $productData[$attributeCode] = $product->getAttributeText($attributeCode);
                }
            }
        }

        $data = array_merge($data, $productData);

        return $data;
    }
411901
public function actionCreate()
    {
        $model = $this->module->model('User');
        $model->loadDefaultValues();
        $model->status = $model::STATUS_DELETED;
        $model->scenario = $model::SCENARIO_CREATE;
        $model->pageSize = intval($this->module->params['pageSizeAdmin']);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index', 'page' => $model->page, 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
                'rolesModels' => [],
            ]);
        }
    }
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;
    }
195114
private function applyCalculations()
    {
        $currency = Yii::$app->params['currency'];

        foreach ($this->models as $position) {
            $id = $position->id;

            $calculation = $this->getCalculation($id);
            if (!$calculation instanceof Calculation) {
                Yii::error('Cart position "' . $position->getName() . '" was removed from the cart because of failed value calculation. Normally this should never happen.', 'hipanel.cart');
                $this->cart->removeById($position->id);
                break;
            }

            $value = $calculation->forCurrency($currency);
            if (!$value instanceof Value) {
                Yii::error('Cart position "' . $position->getName() . '" was removed from the cart because calculation for currency "' . $currency . '" is not available', 'hipanel.cart');
                $this->cart->removeById($position->id);
                break;
            }

            $position->setPrice($value->price);
            $position->setValue($value->value);
        }
    }
87277
public function add() {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data);
            if ($this->Users->save($user)) {
                $this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }
        $this->set(compact('user'));
        $this->set('_serialize', ['user']);
        $this->filteredSelectOptions();
    }
604584
public void addAllToCart()
    {
        for (Product item : searchResults) {
            Boolean selected = searchSelections.get(item);
            if (selected != null && selected) {
                searchSelections.put(item, false);
                cart.addProduct(item, 1);
            }
        }
    }
360500
public function CartForm()
    {   
        $form = Form::create(
            $this,
            "CartForm",
            FieldList::create(),
            FieldList::create(
                FormAction::create(
                    'doUpdate',
                    _t('ShoppingCart.UpdateCart', 'Update Cart')
                )->addExtraClass('btn btn-info')
            )
        )->setTemplate("SilverCommerce\ShoppingCart\Forms\Includes\ShoppingCartForm");
        
        $this->extend("updateCartForm", $form);
        
        return $form;
    }
830516
public function add(array $product, array $data)
    {
        $result = array();
        $this->hook->attach('cart.add.product.before', $product, $data, $result, $this);

        if (!empty($result)) {
            return (array) $result;
        }

        $data += array(
            'quantity' => 1,
            'user_id' => $this->cart->getUid(),
            'store_id' => $product['store_id'],
            'product_id' => $product['product_id']
        );

        $data['cart_id'] = $this->set($data);

        if (empty($data['cart_id'])) {
            return $this->getResultError();
        }

        $result = $this->getResultAdded($data);
        $this->hook->attach('cart.add.product.after', $product, $data, $result, $this);
        return (array) $result;
    }
1095509
def add_to_cart(item_id):
    
    cart = Cart(session['cart'])
    if cart.change_item(item_id, 'add'):
        session['cart'] = cart.to_dict()
    return list_products()
1176674
public function actionCreate()
    {
        Yii::$app->getResponse()->format = Response::FORMAT_JSON;
        $routes = Yii::$app->getRequest()->post('route', '');
        $routes = preg_split('/\s*,\s*/', trim($routes), -1, PREG_SPLIT_NO_EMPTY);
        $model = new AdminRoute();
        $model->addNew($routes);
        return $model->getRoutes();
    }
812722
public function newAction()
    {
        $entity = new ProductOrderItem();
        $form   = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
1331075
public function getCurrentProduct()
    {
        try {
            $product = $this->coreRegistry->registry('current_product');
            if ($product instanceof Product) {
                return [
                    'sku' => $product->getSku(),
                    'id'  => $product->getId(),
                ];
            }
        } catch (\Exception $e) {
            throw $e;
        }

        return false;
    }
1186724
public function transportSessionDataToDB()
    {
        if ($this->saveToDataBase === true) {
            $session = Yii::$app->session;

            if ($session->has(self::SESSION_KEY)) {

                $order = $this->getIncompleteOrderFromDB();
                $products = $session[self::SESSION_KEY];

                foreach ($products as $product) {
                    $orderProduct = $this->getOrderProduct($order->id, $product['id'], $product['combinationId']);
                    $orderProduct->count += $product['count'];
                    if ($orderProduct->validate()) {
                        $orderProduct->save();

                        if (!empty($product['additionalProducts'])) {
                            foreach ($product['additionalProducts'] as $productAdditionalProduct) {
                                $additionalProduct = OrderProductAdditionalProduct::find()
                                    ->where([
                                        'order_product_id' => $orderProduct->id,
                                        'additional_product_id' => $productAdditionalProduct['productId']
                                    ])->one();
                                if (empty($additionalProduct)) {
                                    $additionalProduct = new OrderProductAdditionalProduct();
                                    $additionalProduct->order_product_id = $orderProduct->id;
                                    $additionalProduct->additional_product_id = $productAdditionalProduct['productId'];
                                    $additionalProduct->number = $productAdditionalProduct['number'];
                                    if ($additionalProduct->validate()) $additionalProduct->save();
                                }
                                else {
                                    $additionalProduct->number += $productAdditionalProduct['number'];
                                    if ($additionalProduct->validate()) $additionalProduct->save();
                                }
                            }
                        }
                    }
                }
            }
        }
    }