Answer the question
In order to leave comments, you need to log in
How to edit a property when creating an order?
Hello !
I'm trying to edit a property when creating an order:
use Bitrix\Main;
Main\EventManager::getInstance()->addEventHandler(
'sale',
'OnSaleOrderBeforeSaved',
'onBeforeOrderSaveHandler'
);
function onBeforeOrderSaveHandler(Main\Event $event)
{
/** @var \Bitrix\Sale\Order $order */
$order = $event->getParameter('ENTITY');
$oldPrice = $order->getField('PRICE');
$newval = CCurrencyRates::ConvertCurrency($oldPrice, "EUR", "RUB");
$newPrice = round($newval);
$propertyCode = 'new_price';
/** @var \Bitrix\Sale\PropertyValue $property */
foreach ($order->getPropertyCollection() as $property) {
if ($property->getField('CODE') === $propertyCode) {
$property->setValue($newPrice);
}
}
$saveResult = $order->getPropertyCollection()->save();
}
function submitOrder(form) {
$('.js_ord').hide();
$('#preloader').show();
var pric = $("#price_delivery_id").val();
if($("#deliveryTypesBlock .selected input[name='DELIVERY_ID']").data("ourdelivery") != 1){
$("#price_delivery_id").val(0);
}
if($('[name="DELIVERY_ID"]:checked').val() == 2){
$("#price_delivery_id").val(pric);
$("input[name='ORDER_PROP_22']").val(pric)
}
var fname = $("input[name='ORDER_PROP_8']").val();
var lname = $("input[name='ORDER_PROP_9']").val();
var email = $("input[name='ORDER_PROP_2']").val();
$.ajax({
method: "POST",
url: "/ajax/mailchump_integrate.php",
data: { email: email, fname: fname, lname: lname }
});
var err=false;
$('.pane.last').find('.pane-errors ul').empty()
$('.pane').each(function(){
var $pane = $(this);
errors = validatePane($pane, "required")
if(errors.length) {
for(var i = 0, l = errors.length; i < l; ++i) {
$('.pane.last').find('.pane-errors ul').append($("<li>" + errors[i] + "</li>"));
err =true;
}
}
})
if(err)return false;
$( '#price_delivery_id' ).val( 0 );
var data = $(form).serialize();
$.ajax({
url: $(form).attr('action'),
data: data,
type: "post",
success: function(response) {
console.log(response);
if(response['order']["REDIRECT_URL"]) {
location.href = response['order']["REDIRECT_URL"];
}
var propertyErrors = response['order']["ERROR"]["PROPERTY"];
if(propertyErrors) {
for(var i in propertyErrors) {
$('.errors ul').append($("<li>" + propertyErrors[i] + "</li>"))
}
}
}
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question