该数据库包含“Box 2 - 12 cells”类型的产品。他们没有将产品充分划分为 11 种产品,而是制作了 1 种带有签名的产品。我来了,需要以某种方式自动化计数过程。计算时使用数据库中的数据,最重要的是体积和重量。我尝试使用多个字段作为解决方案,期望在输出中得到 2 个数组。 1 - 重量,2 - 体积。
然而,我得到的输出只是选项的乘法。也就是我得到了11*11的组合。
我只展示一部分
为了从 php 输出,我使用以下代码:
$arSort = array("SORT" => "ASC", "NAME" => "ASC");
$arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y");
$arSelect = array("ID", "NAME", "PROPERTY_FILTER_PRICE", "PROPERTY_PR_VES","PROPERTY_PROD_VOLUME" , "DETAIL_PICTURE", "DETAIL_TEXT");
$obIBlockResult = CIBlockElement::GetList($arSort, $arFilter, false, false, $arSelect);
$data = array();
while ($arFields = $obIBlockResult->GetNext()) {
$data[] = $arFields;
}
if (isset($_GET['ELEMENT_ID'])) {
$elementId = intval($_GET["ELEMENT_ID"]);
$obIBlockResult = CIBlockElement::GetByID($elementId);
if ($obIBlockResult && $obIBlockResult->SelectedElement()) {
$result = [];
while ($ob = $obIBlockResult->GetNextElement()) {
$arFields = $ob->GetFields();
$arProps = $ob->GetProperties();
$result[] = $arProps;
}
echo json_encode($result);
} else {
http_response_code(404);
echo "Элемент не найден";
}
}
这是js
$("#chooseProduct").on("change.select2", function (e) {
var selectedId = e.target.value;
var selectedElement = null;
var elements = <?= json_encode($data) ?>;
console.log(elements) // Именно на этом этапе мне выводит 121 элемент
$('#product-image').css('display', 'flex');
$('#product-image').html(' <div class="circle"></div> <div class="circle" style = "animation-delay: 0.5s;"> </div> <div class="circle" style="animation-delay: 1s;"></div>');
for (var i = 0; i < elements.length; i++) {
if (elements[i].ID === selectedId) {
selectedElement = elements[i];
break;
}
}
$.ajax({
url: "?DETAIL_IMAGE=" + selectedElement.DETAIL_PICTURE,
success: function (pictureUrl) {
if (pictureUrl) {
$('#product-image').html('');
$('#product-image').css('display', 'inline');
$('<img>').attr('src', pictureUrl).attr('width', '400').attr('height', '400').appendTo('#product-image');
$('<div class="production-description">')
.html(selectedElement.DETAIL_TEXT)
.appendTo('#product-image');
$("#window").show()
} else {
$('#product-image').html('');
}
}
});
$('.money-count').text(`${selectedElement.PROPERTY_FILTER_PRICE_VALUE} рублей`);
updateTotalPrice();
window.selectedElement = selectedElement
})
;
function setPriceFields(product) {
$(".money-count").textContent = product.price
$(".total-money-count").textContent = product.price * product.count
}
function addProductToList() {
let counter = $('#count')[0];
let product = {}
console.log(selectedElement)
product.name = selectedElement.NAME;
product.priceForOne = parseFloat(selectedElement.PROPERTY_FILTER_PRICE_VALUE)
product.params = []
product.params.push(["Вес", selectedElement.PROPERTY_PR_VES_VALUE])
product.weight = parseFloat(selectedElement.PROPERTY_PR_VES_VALUE) * counter.value;
product.volume = parseFloat(selectedElement.PROPERTY_PROD_VOLUME_VALUE) * counter.value;
product.count = parseInt(counter.value)
product.priceForAll = parseFloat(product.priceForOne * product.count)
console.log(product)
counter.value = 1
window.products.push(product)
$("#product-image").hide()
clearPriceFields()
clearFirstSelect()
$(".button-container").show();
$(".adding_info").show();
}
或者,做
然后循环
fetchObject
获取数据