A
A
anriko2020-12-04 08:46:53
1C-Bitrix
anriko, 2020-12-04 08:46:53

How to transfer related products to the cart in the catalog.item catalog?

Here it is passed via url: this.basketUrl, product id .but I also need to pass the anchor id to the product, how can I do this?
And if you wrap BX.ajax in a loop, then I don’t know where to get the price codes for related products basket_props: "YToxOntpOjA7czo5OiJBTktFUlNfSU0iO30="

sendToBasket: function()
    {
      if (!this.canBuy)
      {
        return;
      }

      // check recommendation
      if (this.product && this.product.id && this.bigData)
      {
        this.rememberProductRecommendation();
      }

      this.initBasketUrl();
      this.fillBasketProps();
      BX.ajax({
        method: 'POST',
        dataType: 'json',
        url: this.basketUrl, //"/polimernye-kolesootbojniki/?action=ADD2BASKET&id=16998"
        data: this.basketParams, // ajax_basket: "Y"basket_props: "YToxOntpOjA7czo5OiJBTktFUlNfSU0iO30="quantity: "16"
        onsuccess: BX.proxy(this.basketResult, this)
      });
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anriko, 2020-12-04
@anriko

did it, maybe someone can fix it

sendToBasket: function()
    {
      if (!this.canBuy)
      {
        return;
      }

      // check recommendation
      if (this.product && this.product.id && this.bigData)
      {
        this.rememberProductRecommendation();
      }

      this.initBasketUrl();
      this.fillBasketProps();
      var url = this.basketUrl.split('id=')[0] + 'id=';
      var arrid = [];
      var basketParams = [];
      var idmaintov = this.arParamsCustom.PRODUCT.ID;
      arrid.push(this.basketUrl.split('id=')[1]);
      basketParams.push(this.basketParams);
// получает количесво и id товара анкера
      if($('#ankers'+idmaintov).val() > 0) {
        arrid.push($('#ankers'+idmaintov).data('id'));
        var ankersq = Object.assign({}, this.basketParams);
        ankersq.quantity = $('#ankers'+idmaintov).val();
        basketParams.push(ankersq);
      }
// получает количесво и id услуги монтаж 1 анкера
      if($('#construction'+idmaintov).prop('checked') && $('#ankers'+idmaintov).val() > 0){
        arrid.push($('#construction'+idmaintov).data('id'));
        var construction = Object.assign({}, this.basketParams);
        construction.quantity  = $('#ankers'+idmaintov).val();
        basketParams.push(construction);

      }
      for (let i = 0; i < arrid.length; i++){

        BX.ajax({
          method: 'POST',
          dataType: 'json',
          url: url + arrid[i] ,
          data: basketParams[i],
          onsuccess: BX.proxy(this.basketResult, this)
        });
      }


    },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question