Adds new product to the current shopping cart
353449
def post(self, request, *args, **kwargs):
        
        POST = json.loads(request.body.decode('utf-8'))

        if 'product_pk' in POST and 'quantity' in POST:
            cart = ShoppingCartProxy(request)
            cart.add(
                product_pk=int(POST['product_pk']),
                quantity=int(POST['quantity'])
            )
            return JsonResponse(cart.products)

        return HttpResponseBadRequest()
233198
def addItem(self, child, href):
        """"""
        assert isinstance(child, Base), "child must be a hypercat Catalogue or Resource"
        child.setHref(href)
        for item in self.items:
            assert item.href != href, "All items in a catalogue must have unique hrefs : "+href
        self.items += [child]           # Add new
        return
808463
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
    {
        if ($this->isMulti($id)) {
            return array_map(function ($item) {
                return $this->add($item);
            }, $id);
        }

        $cartItem = $this->createCartItem($id, $name, $qty, $price, $options);

        $content = $this->getContent();

        if ($content->has($cartItem->rowId)) {
            $cartItem->qty += $content->get($cartItem->rowId)->qty;
        }

        $content->put($cartItem->rowId, $cartItem);
        
        $this->events->fire('cart.added', $cartItem);

        $this->session->put($this->instance, $content);

        return $cartItem;
    }
1167424
def add_item(self, item):
        """"""
        _idx = len(self.items)
        self.items.update({"item_" + str(_idx + 1): item})
776304
public Completable addProduct(Product product) {
    List<Product> updatedShoppingCart = new ArrayList<>();
    updatedShoppingCart.addAll(itemsInShoppingCart.getValue());
    updatedShoppingCart.add(product);
    itemsInShoppingCart.onNext(updatedShoppingCart);
    return Completable.complete();
  }
564938
def add(self, item):
        """"""
        self._check_index()
        # Possibly truncate the history up to the current point.
        self._history = self._history[:self._index + 1]
        # Append the item
        self._history.append(item)
        # Increment the index.
        self._index += 1
        self._check_index()
        # Check that the current element is what was provided to the function.
        assert id(self.current_item) == id(item)
283403
def add_item(self, item, **options):
        
        export_item = {
            "item": item.url,
        }
        export_item.update(options)
        self.items.append(export_item)
        return self
44549
public function addCartItem($cartId, $cartItem)
    {
        $cartItem = $this->arraySnakeCase($cartItem);

        $cartItem['cart_id'] = $cartId;
        CartItem::create($cartItem);
    }
29424
def add(item, quantity: 1, unique: true)
      raise 'expecting an acts_as_purchasable object' unless item.kind_of?(ActsAsPurchasable)

      existing = (
        if unique.kind_of?(Proc)
          cart_items.find { |cart_item| instance_exec(item, cart_item.purchasable, &unique) }
        elsif unique.kind_of?(Symbol) || (unique.kind_of?(String) && unique != 'true')
          raise "expected item to respond to unique #{unique}" unless item.respond_to?(unique)
          cart_items.find { |cart_item| cart_item.purchasable.respond_to?(unique) && item.send(unique) == cart_item.purchasable.send(unique) }
        elsif unique.present?
          find(item)
        end
      )

      if existing
        if unique || (existing.unique.present?)
          existing.assign_attributes(purchasable: item, quantity: quantity, unique: existing.unique)
        else
          existing.quantity = existing.quantity + quantity
        end
      end

      if item.quantity_enabled? && (existing ? existing.quantity : quantity) > item.quantity_remaining
        raise EffectiveOrders::SoldOutException, "#{item.purchasable_name} is sold out"
      end

      existing ||= cart_items.build(purchasable: item, quantity: quantity, unique: (unique.to_s unless unique.kind_of?(Proc)))
      save!
    end
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;
    }
1074027
def add(product_object, amount=nil, unit=nil)
      product_object = (product_object)
      product_object.amount = amount if amount
      product_object.unit = unit if unit

      cart_item_params = product_object.to_cart_item_params
      existing_item = find_item(cart_item_params)

      if existing_item
        existing_item.inc(amount: cart_item_params[:amount])
      else
        cart_items.create!(cart_item_params)
      end
    end
191700
def after_add_or_remove(line_item, options = {})
      line_item = super
      Spree::Cart::Event::Tracker.new(
        actor: order, target: line_item, total: order.total, variant_id: line_item.variant_id
      ).track
      line_item
    end
175407
function dataLayer_updateBasket(thisID, thisBtnPos, type) {
      var thisParagraph = allRows[thisID];
      var thisAmount = '';
      var isBtn = true;

      // Construct generic ecommerce object for all use cases
      // TODO: handle currency changes
      var ecommerceObj = {
        'ecommerce': {'currencyCode': 'GBP',},
        'event': type ===  'add' ? 'addToBasket' : 'removeFromBasket'
      };

      lastBtnPos = thisBtnPos;

      // Change our 'amount' source depending on the input type
      if (thisBtnPos == 0) {
        isBtn = false;
        thisAmount = $('#' + thisID).data('current-amount');
      } else {
        thisAmount = allRows[thisID]['buttons'][thisBtnPos]['amount'];
      }

      submitNameID = isBtn ? 'moneybuy-' + thisAmount : 'manual-entry';

      // Parse this to a 2-decimal place float, need to re-parse after toFixed
      thisAmount = parseFloat(thisAmount).toFixed(2);
      thisAmount = parseFloat(thisAmount);

      // Switch the values based on the input type
      ecommerceObj['ecommerce'][type] = {
        'actionField': {'list': thisParagraph['client_id'] + '_' + thisID },
        'products': [{
          id: submitNameID,
          name: submitNameID,
          price: thisAmount,      
          brand: allRows[thisID]['giving_type'],  
          category: allRows[thisID]['cart_id'], 
          quantity: 1,
          dimenstion10: allRows[thisID]['giving_type']
        }],
      };

      dataLayer.push(ecommerceObj);

      // If this is our 'add' event triggered via submission, add the new cookie
      if ( type === 'add' ){
        updateCookie(thisID, thisBtnPos, 'add');
      }
    }
276883
def on_add(self, item):
        """"""
        super(Tels, self).on_add(list_views.PseudoAccesCategorie(item))
916372
def addDataProducts(self, dps):
        
        busy = Purr.BusyIndicator()
        wakeup = False
        # build up list of items to be inserted
        itemlist = []
        for dp in dps:
            item = self.dpitems.get(dp.sourcepath)
            # If item already exists, it needs to be moved to its new position
            # If takeTopLevelItem() returns None, then item was already removed (this shouldn't happen,
            # but let's be defensive), and we make a new one anyway.
            if item and self.takeTopLevelItem(self.indexOfTopLevelItem(item)):
                itemlist.append(item)
            else:
                itemlist.append(self._makeDPItem(None, dp))
            wakeup = wakeup or not (dp.ignored or dp.quiet)
        # if these DPs were added as a result of a drag-and-drop, we need to insert them in FRONT of the dropped-on item
        if self._dropped_on:
            index = self.indexOfTopLevelItem(self._dropped_on)
        # else insert at end (after=None)
        else:
            index = self.topLevelItemCount()
        if itemlist:
            self.insertTopLevelItems(index, itemlist)
            self.emit(SIGNAL("updated"))
        for item in itemlist:
            # ensure combobox widgets are made
            self._itemComboBox(item, self.ColAction)
            self._itemComboBox(item, self.ColRender)
        return wakeup
219022
private function addItem()
    {
        $args = func_get_args();
        $this->items[$args[0]] = implode(':', array_slice($args, 1));

        return $this;
    }
256139
function _add_item(in_arg_key, data){

	var retval = false;
	if( typeof anchor.current_data[in_arg_key] == 'undefined' ){
	    // BUG/TODO: this should be a copy.
	    anchor.current_data[in_arg_key] = data;
	    //ll("add_item: adding key (w/data): " + in_arg_key);
	    retval = true;
	}
	return retval;
    }