I
I
Ivan Kasatkin2021-08-25 09:36:20
1C-Bitrix
Ivan Kasatkin, 2021-08-25 09:36:20

How to clone an element if the quantity is "2"?

We have code that does

So

6125e3fd29c62442029980.png

But you must
So
6125e4358e78b829141734.png

In ordinary words, I need that if the amount is "2", then two pictures appear, not one.
Here
the code
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=<?=LANG_CHARSET?>">
  <title langs="ru">Картинки 2.0</title> <!--Написал Dublet(Vk.com/vanyapanin) 25.08.21-->
<style>
<!--
.header{font-size:17px; font-family:Tahoma;padding-left:8px;}
.sub_header{font-size:13px; font-family:Tahoma;padding-left:8px;}
.date{font-style:italic; font-family:Tahoma;padding-left:8px;}
.number{font-size:24px;font-family:Tahoma;font-style:italic;padding-left:8px;}
.user{font-size:12px;font-family:Tahoma;font-weight:bold;padding-left:8px;}
.summa{font-size:12px;font-family:Tahoma;font-weight:bold;padding-left:15px;}

table.blank {
  border-collapse: collapse;
  width: 320px;
}
table.blank td {
  border:0.5pt solid windowtext;
}
-->
</style>
<script>
var template;

function createTemplate() {
  template = $('.html-to-copy').eq(0).clone();
  template = template.addClass('modify');
}

$('button')
  .one('click', createTemplate)
  .on('click', function(){
    $('.container').append(template);
})
</script>
</head>

<body bgcolor=white lang=RU style='tab-interval:35.4pt'>

<?
$page = intval($page);
if ($page<=0) $page = 1;
?>
<div class="container"><div class="html-to-copy">
<table height="800" align="left" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td colspan="3">

      <br>

      <?
      if (count($arBasketIDs)>0)
      {
        $arCurFormat = CCurrencyLang::GetCurrencyFormat($arOrder["CURRENCY"]);
        $currency = preg_replace('/(^|[^&])#/', '${1}', $arCurFormat['FORMAT_STRING']);
        ?>
        <table class="blank">
          <tr>
            <td align="center" style="opacity:0;border:0;"> <font size='2'>№</font></td>
            <td align="center">Количество</td>
            <td align="center"> <font size='2'>Наименование</font></td>
            <td align="center"><font size='2'>Изображение</font></td>
            <td align="left"><font size='2'>Характеристики</font></td>
            <td align="center"><font size='2'>Артикул</font></td>

          </tr>

          <?
          $priceTotal = 0;
          $bUseVat = false;
          $arBasketOrder = array();
          for ($i = 0, $countBasketIds = count($arBasketIDs); $i < $countBasketIds; $i++)
          {
            $arBasketTmp = CSaleBasket::GetByID($arBasketIDs[$i]);
            if (floatval($arBasketTmp["VAT_RATE"]) > 0 )
              $bUseVat = true;
            $priceTotal += $arBasketTmp["PRICE"]*$arBasketTmp["QUANTITY"];

            $arBasketTmp["PROPS"] = array();
            if (isset($_GET["PROPS_ENABLE"]) && $_GET["PROPS_ENABLE"] == "Y")
            {
              $dbBasketProps = CSaleBasket::GetPropsList(
                  array("SORT" => "ASC", "NAME" => "ASC"),
                  array("BASKET_ID" => $arBasketTmp["ID"]),
                  false,
                  false,
                  array("ID", "BASKET_ID", "NAME", "VALUE", "CODE", "SORT")
                );
              while ($arBasketProps = $dbBasketProps->GetNext())
                $arBasketTmp["PROPS"][$arBasketProps["ID"]] = $arBasketProps;
            }



            $arBasketOrder[] = $arBasketTmp;
          }

          //разбрасываем скидку на заказ по товарам
          if (floatval($arOrder["DISCOUNT_VALUE"]) > 0)
          {
            $arBasketOrder = GetUniformDestribution($arBasketOrder, $arOrder["DISCOUNT_VALUE"], $priceTotal);
          }

          //налоги
          $arTaxList = array();
          $db_tax_list = CSaleOrderTax::GetList(array("APPLY_ORDER"=>"ASC"), Array("ORDER_ID"=>$ORDER_ID));
          $iNds = -1;
          $i = 0;
          while ($ar_tax_list = $db_tax_list->Fetch())
          {
            $arTaxList[$i] = $ar_tax_list;
            // определяем, какой из налогов - НДС
            // НДС должен иметь код NDS, либо необходимо перенести этот шаблон
            // в каталог пользовательских шаблонов и исправить
            if ($arTaxList[$i]["CODE"] == "NDS")
              $iNds = $i;
            $i++;
          }

          $i = 0;
          $total_sum = 0;
          foreach ($arBasketOrder as $arBasket):
            $nds_val = 0;
            $taxRate = 0;

            if (floatval($arQuantities[$i]) <= 0)
              $arQuantities[$i] = DoubleVal($arBasket["QUANTITY"]);

            $b_AMOUNT = DoubleVal($arBasket["PRICE"]);

            //определяем начальную цену
            $item_price = $b_AMOUNT;

            if(DoubleVal($arBasket["VAT_RATE"]) > 0)
            {
              $nds_val = ($b_AMOUNT - DoubleVal($b_AMOUNT/(1+$arBasket["VAT_RATE"])));
              $item_price = $b_AMOUNT - $nds_val;
              $taxRate = $arBasket["VAT_RATE"]*100;
            }
            elseif(!$bUseVat)
            {
              $basket_tax = CSaleOrderTax::CountTaxes($b_AMOUNT*$arQuantities[$i], $arTaxList, $arOrder["CURRENCY"]);
              for ($mi = 0, $countTaxList = count($arTaxList); $mi < $countTaxList; $mi++)
              {
                if ($arTaxList[$mi]["IS_IN_PRICE"] == "Y")
                {
                  $item_price -= $arTaxList[$mi]["TAX_VAL"];
                }
                $nds_val += DoubleVal($arTaxList[$mi]["TAX_VAL"]);
                $taxRate += ($arTaxList[$mi]["VALUE"]);
              }
            }
          ?>
<?
$A = Bitrix\Sale\BasketItem::formatQuantity($arQuantities[$i])
?>
          <tr>
            <td style="border: 0;opacity: 0;"><?echo $i+1;?></td>
<td align="center"><?echo $A?></td>
<td> <font size='2'>
              <?echo htmlspecialcharsbx($arBasket["NAME"]);?> </font>
              <?
              if (is_array($arBasket["PROPS"]) && $_GET["PROPS_ENABLE"] == "Y")
                  {
                    foreach($arBasket["PROPS"] as $vv)
                    {
                      if($vv["VALUE"] <> '' && $vv["CODE"] != "CATALOG.XML_ID" && $vv["CODE"] != "PRODUCT.XML_ID")
                        echo "<div style=\"font-size:8pt\">".$vv["NAME"].": ".$vv["VALUE"]."</div>";
                    }
                  }
              ?>
            </td>



            <td align="right" nowrap><?  $res = CIBlockElement::GetByID($arBasket['PRODUCT_ID']); 
if($ar_res = $res->GetNext()) 
$imagepath= CFile::GetPath($ar_res['DETAIL_PICTURE']);?><img width="150" height="150" src='http://<?=$SERVER_NAME.$imagepath  ?>'</td> <!--Вставить картинку из товара-->



<!--Вставить Описание--><?
  $arTemp = CIBlockElement::GetList(
      array(), 
      array(
       'IBLOCK_ID' => 21, 
       'ID' => $arBasket['PRODUCT_ID']
      ), false, false, array(
        'ID',
        'IBLOCK_ID',
        'DETAIL_TEXT')
  )->Fetch();
?>
<td align="left"><font size='2'><?echo htmlspecialchars($arTemp["DETAIL_TEXT"]);?></font>

<!--Вставить Артикул--> <? 
  $arElement = CIBlockElement::GetList( 
      array(), 
      array(
       'IBLOCK_ID' => 21, 
       'ID' => $arBasket['PRODUCT_ID']
      ), false, false, array(
        'ID',
        'IBLOCK_ID',
        'PROPERTY_CML2_ARTICLE')
  )->Fetch();
?>
<td><font size='2'><?echo htmlspecialchars($arElement["PROPERTY_CML2_ARTICLE_VALUE"]);?></font>
<? $zero='<tr><td style="border: 0;opacity: 0"><br><br><br><br><br><br></td></tr>';
        if ($i >= 7 and 8 > $i) {echo $zero;}
        if ($i >= 15 and 16 > $i) {echo $zero;}
        if ($i >= 23 and 24 > $i) {echo $zero;}
        if ($i >= 31 and 32 > $i) {echo $zero;}
        if ($i >= 39 and 40 > $i) {echo $zero;}
        if ($i >= 47 and 48 > $i) {echo $zero;}
        if ($i >= 55 and 56 > $i) {echo $zero;}
        if ($i >= 63 and 64 > $i) {echo $zero;}
        if ($i >= 71 and 72 > $i) {echo $zero;}
        if ($i >= 79 and 80 > $i) {echo $zero;}
        if ($i >= 87 and 88 > $i) {echo $zero;}
        if ($i >= 95 and 96 > $i) {echo $zero;}
            ?>
<?
$B='AS';
if ($A >= 2) {echo $B;}
?>
</tr></td>

          <?
          if (empty($arBasket['SET_PARENT_ID']))
          {
            $total_sum += $arBasket["PRICE"]*$arQuantities[$i];
            $total_nds += $nds_val*$arQuantities[$i];
          }
          $i++;
          endforeach;
          ?>

        <?
      }
      ?>
</table></div></div>
  </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tgarl, 2021-08-25
@Dublet

Honestly, I don’t want to poke around in your code, you have a lot of extra requests there.
But the meaning of solving your problem is this:
you have a code that forms a string

<tr>
            <td style="border: 0;opacity: 0;"><?echo $i+1;?></td>
<td align="center"><?echo $A?></td>
...

so check your number $A
if more than 1 then make a loop inside which the output, otherwise - output as it is.
if($A>1){
    for(){
           // то что имеете сейчас, но в цикле
           ?><tr><td style="border: 0;opacity: 0;"><?echo $i+1;?></td><td ...<?
       }
}else{
           //то что имеете сейчас
            ?><tr><td style="border: 0;opacity: 0;"><?echo $i+1;?></td><td ...<?
     }
}

just take note
It's not for nothing that the components have a division into the file result_modifier and template - this is essentially an aid in separating logic. Those. You first do all the necessary manipulations, queries, form the final array, and work with the resulting array in the template. So you need to refactor your code, separate it into processing and template. And you have everything in a heap, so you don’t see the solution. And add a loop into which you will push duplicate requests (with your code, this is exactly what will happen) and get that the page loads for a long time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question