src/Cart/Manager.php
public function add($slug, $qty, $attribute = null): Manager
    {
        $cartProducts = $this->getSession();
        $product = Product::whereSlug($slug)->first();
        $price = $product->price;
        $attributes = null;

        if (null !== $attribute && count($attribute)) {

            foreach ($attribute as $attributeId => $attributeValueId) {
                if ('variation_id' == $attributeId) {
                    continue;
                }
                $variableProduct = Product::find($attribute['variation_id']);
                $attributeModel = Attribute::find($attributeId);

                $productAttributeIntValModel = ProductAttributeIntegerValue::
                    whereAttributeId($attributeId)
                    ->whereProductId($variableProduct->id)
                    ->first();

                $optionModel = $attributeModel
                    ->AttributeDropdownOptions()
                    ->whereId($productAttributeIntValModel->value)
                    ->first();

                $price = $variableProduct->price;
                $attributes[] = [
                    'attribute_id' => $attributeId,
                    'variation_id' => $variableProduct->id,
                    'attribute_dropdown_option_id' => $optionModel->id,
                    'variation_display_text' => $attributeModel->name . ': ' . $optionModel->display_text
                ];
            }
        }

        $cartProduct = new CartFacadeProduct();
        $cartProduct->name($product->name)
                    ->qty($qty)
                    ->slug($slug)
                    ->price($price)
                    ->image($product->image)
                    ->lineTotal($qty * $price)
                    ->attributes($attributes);

        $cartProducts->put($slug, $cartProduct);

        $this->sessionManager->put($this->getSessionKey(), $cartProducts);

        return $this;
    }
public function add($slug, $qty, $attribute = null): Manager
    {
        $cartProducts = $this->getSession();
        $product = Product::whereSlug($slug)->first();
        $price = $product->price;
        $attributes = null;

        if (null !== $attribute && count($attribute)) {

            foreach ($attribute as $attributeId => $attributeValueId) {
                if ('variation_id' == $attributeId) {
                    continue;
                }
                $variableProduct = Product::find($attribute['variation_id']);
                $attributeModel = Attribute::find($attributeId);

                $productAttributeIntValModel = ProductAttributeIntegerValue::
                    whereAttributeId($attributeId)
                    ->whereProductId($variableProduct->id)
                    ->first();

                $optionModel = $attributeModel
                    ->AttributeDropdownOptions()
                    ->whereId($productAttributeIntValModel->value)
                    ->first();

                $price = $variableProduct->price;
                $attributes[] = [
                    'attribute_id' => $attributeId,
                    'variation_id' => $variableProduct->id,
                    'attribute_dropdown_option_id' => $optionModel->id,
                    'variation_display_text' => $attributeModel->name . ': ' . $optionModel->display_text
                ];
            }
        }

        $cartProduct = new CartFacadeProduct();
        $cartProduct->name($product->name)
                    ->qty($qty)
                    ->slug($slug)
                    ->price($price)
                    ->image($product->image)
                    ->lineTotal($qty * $price)
                    ->attributes($attributes);

        $cartProducts->put($slug, $cartProduct);

        $this->sessionManager->put($this->getSessionKey(), $cartProducts);

        return $this;
    }
public function add ( $ slug , $ qty , $ attribute = null ) : Manager { $ cartProducts = $ this -> getSession ( ) ; $ product = Product :: whereSlug ( $ slug ) -> first ( ) ; $ price = $ product -> price ; $ attributes = null ; if ( null !== $ attribute && count ( $ attribute ) ) { foreach ( $ attribute as $ attributeId => $ attributeValueId ) { if ( 'variation_id' == $ attributeId ) { continue ; } $ variableProduct = Product :: find ( $ attribute [ 'variation_id' ] ) ; $ attributeModel = Attribute :: find ( $ attributeId ) ; $ productAttributeIntValModel = ProductAttributeIntegerValue :: whereAttributeId ( $ attributeId ) -> whereProductId ( $ variableProduct -> id ) -> first ( ) ; $ optionModel = $ attributeModel -> AttributeDropdownOptions ( ) -> whereId ( $ productAttributeIntValModel -> value ) -> first ( ) ; $ price = $ variableProduct -> price ; $ attributes [ ] = [ 'attribute_id' => $ attributeId , 'variation_id' => $ variableProduct -> id , 'attribute_dropdown_option_id' => $ optionModel -> id , 'variation_display_text' => $ attributeModel -> name . ': ' . $ optionModel -> display_text ] ; } } $ cartProduct = new CartFacadeProduct ( ) ; $ cartProduct -> name ( $ product -> name ) -> qty ( $ qty ) -> slug ( $ slug ) -> price ( $ price ) -> image ( $ product -> image ) -> lineTotal ( $ qty * $ price ) -> attributes ( $ attributes ) ; $ cartProducts -> put ( $ slug , $ cartProduct ) ; $ this -> sessionManager -> put ( $ this -> getSessionKey ( ) , $ cartProducts ) ; return $ this ; }
Add Product into cart using Slug and Qty.

@param string  $slug
@param int $qty
@param array $attributes
@return \AvoRed\Framework\Cart\Manager $this
Add Product into cart using Slug and Qty .