update
This commit is contained in:
@@ -1,20 +1,52 @@
|
||||
<? if ( $this -> custom_fields ) : ?>
|
||||
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
|
||||
<? $custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key ); ?>
|
||||
|
||||
<? if ( $custom_field['type'] == 'text' ) : ?>
|
||||
<div class="custom-field">
|
||||
<div class="_name">
|
||||
<?
|
||||
echo $custom_field['name'] . ':';
|
||||
?>
|
||||
</div>
|
||||
<div class="_text">
|
||||
<?= $val;?>
|
||||
</div>
|
||||
</div>
|
||||
<? elseif ( $custom_field['type'] == 'image' ) : ?>
|
||||
<div class="custom-fields-display" data-product-code="<?= htmlspecialchars( $this->product_code ); ?>">
|
||||
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
|
||||
<? $custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key ); ?>
|
||||
<? $field_type = !empty( $custom_field['type'] ) ? $custom_field['type'] : 'text'; ?>
|
||||
|
||||
<? endif; ?>
|
||||
<? endforeach; ?>
|
||||
<? endif;?>
|
||||
<? if ( $field_type == 'text' ) : ?>
|
||||
<div class="custom-field">
|
||||
<div class="_name">
|
||||
<?= htmlspecialchars( $custom_field['name'] ) . ':'; ?>
|
||||
</div>
|
||||
<div class="_text">
|
||||
<?= nl2br( htmlspecialchars( $val ) );?>
|
||||
</div>
|
||||
</div>
|
||||
<? elseif ( $field_type == 'image' && !empty( $val ) ) : ?>
|
||||
<div class="custom-field">
|
||||
<div class="_name">
|
||||
<?= htmlspecialchars( $custom_field['name'] ) . ':'; ?>
|
||||
</div>
|
||||
<div class="_image">
|
||||
<img src="<?= htmlspecialchars( $val );?>" alt="<?= htmlspecialchars( $custom_field['name'] );?>">
|
||||
</div>
|
||||
</div>
|
||||
<? endif; ?>
|
||||
<? endforeach; ?>
|
||||
<a href="#" class="btn btn-sm btn-default btn-edit-custom-fields">Edytuj personalizację</a>
|
||||
</div>
|
||||
|
||||
<div class="custom-fields-edit" data-product-code="<?= htmlspecialchars( $this->product_code ); ?>" style="display: none;">
|
||||
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
|
||||
<? $custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key ); ?>
|
||||
<? $field_type = !empty( $custom_field['type'] ) ? $custom_field['type'] : 'text'; ?>
|
||||
<? $is_required = !empty( $custom_field['is_required'] ) ? (int)$custom_field['is_required'] : 0; ?>
|
||||
|
||||
<div class="custom-field-edit-row" style="margin-bottom: 5px;">
|
||||
<label>
|
||||
<?= htmlspecialchars( $custom_field['name'] ); ?><?= $is_required ? ' <span style="color:red;">*</span>' : ''; ?>
|
||||
</label>
|
||||
<? if ( $field_type == 'text' ) : ?>
|
||||
<input type="text" class="form-control form-control-sm" name="custom_field[<?= (int)$key; ?>]" value="<?= htmlspecialchars( $val ); ?>" <?= $is_required ? 'required' : ''; ?>>
|
||||
<? elseif ( $field_type == 'image' ) : ?>
|
||||
<input type="text" class="form-control form-control-sm" name="custom_field[<?= (int)$key; ?>]" value="<?= htmlspecialchars( $val ); ?>" placeholder="URL obrazka" <?= $is_required ? 'required' : ''; ?>>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
<div style="margin-top: 5px;">
|
||||
<a href="#" class="btn btn-sm btn-primary btn-save-custom-fields">Zapisz</a>
|
||||
<a href="#" class="btn btn-sm btn-default btn-cancel-custom-fields">Anuluj</a>
|
||||
</div>
|
||||
</div>
|
||||
<? endif; ?>
|
||||
|
||||
@@ -61,7 +61,8 @@
|
||||
<hr>
|
||||
<? endif; ?>
|
||||
<?= \Shared\Tpl\Tpl::view( 'shop-basket/_partials/product-custom-fields', [
|
||||
'custom_fields' => $position['custom_fields']
|
||||
'custom_fields' => $position['custom_fields'],
|
||||
'product_code' => $position_hash
|
||||
] ); ?>
|
||||
<? if ( $product['additional_message'] ):?>
|
||||
<div class="basket-product-message">
|
||||
|
||||
@@ -1,4 +1,46 @@
|
||||
<? global $settings; ?>
|
||||
<?
|
||||
if ( $settings['google_tag_manager_id'] && is_array( $this -> basket ) && count( $this -> basket ) ):
|
||||
$view_cart_items = '';
|
||||
$view_cart_value = 0;
|
||||
|
||||
foreach ( $this -> basket as $position ):
|
||||
$vc_product = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->findCached( (int)$position['product-id'], (new \Domain\Languages\LanguagesRepository($GLOBALS['mdb']))->defaultLanguage() );
|
||||
|
||||
if ( !$vc_product )
|
||||
continue;
|
||||
|
||||
$vc_price = (float)$vc_product['price_brutto_promo'] > 0 && (float)$vc_product['price_brutto_promo'] < (float)$vc_product['price_brutto']
|
||||
? (float)$vc_product['price_brutto_promo']
|
||||
: (float)$vc_product['price_brutto'];
|
||||
|
||||
$vc_qty = (int)$position['quantity'];
|
||||
$view_cart_value += $vc_price * $vc_qty;
|
||||
|
||||
if ( $view_cart_items )
|
||||
$view_cart_items .= ',';
|
||||
|
||||
$view_cart_items .= '{';
|
||||
$view_cart_items .= 'item_id: "' . $vc_product['id'] . '",';
|
||||
$view_cart_items .= 'item_name: "' . str_replace( '"', '', $vc_product['language']['name'] ) . '",';
|
||||
$view_cart_items .= 'price: ' . \Shared\Helpers\Helpers::normalize_decimal( $vc_price ) . ',';
|
||||
$view_cart_items .= 'quantity: ' . $vc_qty . ',';
|
||||
$view_cart_items .= 'google_business_vertical: "retail"';
|
||||
$view_cart_items .= '}';
|
||||
endforeach;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
dataLayer.push({ ecommerce: null });
|
||||
dataLayer.push({
|
||||
event: "view_cart",
|
||||
ecommerce: {
|
||||
currency: "PLN",
|
||||
value: <?= \Shared\Helpers\Helpers::normalize_decimal( $view_cart_value );?>,
|
||||
items: [<?= $view_cart_items;?>]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<? endif; ?>
|
||||
<div id="basket-container">
|
||||
<div id="content">
|
||||
<?= $this->basket_details; ?>
|
||||
@@ -508,4 +550,62 @@
|
||||
console.warn('#orlen_point_id nie został znaleziony.');
|
||||
}
|
||||
});
|
||||
|
||||
// edycja personalizacji produktu w koszyku
|
||||
$(document).on('click', '.btn-edit-custom-fields', function(e) {
|
||||
e.preventDefault();
|
||||
var $display = $(this).closest('.custom-fields-display');
|
||||
var productCode = $display.data('product-code');
|
||||
$display.hide();
|
||||
$display.siblings('.custom-fields-edit[data-product-code="' + productCode + '"]').show();
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-cancel-custom-fields', function(e) {
|
||||
e.preventDefault();
|
||||
var $edit = $(this).closest('.custom-fields-edit');
|
||||
var productCode = $edit.data('product-code');
|
||||
$edit.hide();
|
||||
$edit.siblings('.custom-fields-display[data-product-code="' + productCode + '"]').show();
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-save-custom-fields', function(e) {
|
||||
e.preventDefault();
|
||||
var $edit = $(this).closest('.custom-fields-edit');
|
||||
var productCode = $edit.data('product-code');
|
||||
|
||||
var valid = true;
|
||||
$edit.find('input[required]').each(function() {
|
||||
if ($.trim($(this).val()) === '') {
|
||||
$(this).css('border-color', 'red');
|
||||
valid = false;
|
||||
} else {
|
||||
$(this).css('border-color', '');
|
||||
}
|
||||
});
|
||||
|
||||
if (!valid) {
|
||||
alert('Wypełnij wszystkie wymagane pola');
|
||||
return;
|
||||
}
|
||||
|
||||
var formData = { product_code: productCode };
|
||||
$edit.find('input[name^="custom_field"]').each(function() {
|
||||
formData[$(this).attr('name')] = $(this).val();
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/shopBasket/basket_update_custom_fields',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
var data = jQuery.parseJSON(response);
|
||||
if (data.result === 'ok') {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Wystąpił błąd');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -73,10 +73,11 @@
|
||||
$begin_checkout_items .= ',';
|
||||
|
||||
$begin_checkout_items .= '{';
|
||||
$begin_checkout_items .= '"id": "' . $product['id'] . '",';
|
||||
$begin_checkout_items .= '"name": "' . $product['language']['name'] . '",';
|
||||
$begin_checkout_items .= '"item_id": "' . $product['id'] . '",';
|
||||
$begin_checkout_items .= '"item_name": "' . str_replace( '"', '', $product['language']['name'] ) . '",';
|
||||
$begin_checkout_items .= '"price": ' . \Shared\Helpers\Helpers::normalize_decimal( $price_product['price_new'] ) . ',';
|
||||
$begin_checkout_items .= '"quantity": ' . $position['quantity'];
|
||||
$begin_checkout_items .= '"quantity": ' . (int)$position['quantity'] . ',';
|
||||
$begin_checkout_items .= '"google_business_vertical": "retail"';
|
||||
$begin_checkout_items .= '}';
|
||||
?>
|
||||
<? endforeach;?>
|
||||
|
||||
@@ -169,17 +169,17 @@
|
||||
event: "purchase",
|
||||
ecommerce: {
|
||||
transaction_id: "<?= $this -> order['id'];?>",
|
||||
value: 25.42,
|
||||
currency: "PLN",
|
||||
value: <?= \Shared\Helpers\Helpers::normalize_decimal( round( $this -> order['summary'], 2 ) ) - str_replace( ',', '.', round( $this -> order['transport_cost'], 2 ) );?>,
|
||||
shipping: <?= \Shared\Helpers\Helpers::normalize_decimal( $this -> order['transport_cost'] );?>,
|
||||
items: [
|
||||
<? foreach ( $this -> order['products'] as $product ):?>
|
||||
{
|
||||
'id': <?= (int)$product['product_id'];?>,
|
||||
'name': '<?= $product['name'];?>',
|
||||
'quantity': <?= $product['quantity'];?>,
|
||||
'price': <?= ((float)$product['price_brutto_promo'] > 0 && (float)$product['price_brutto_promo'] < (float)$product['price_brutto']) ? (float)$product['price_brutto_promo'] : (float)$product['price_brutto'];?>
|
||||
item_id: "<?= $product['product_id'];?>",
|
||||
item_name: "<?= str_replace( '"', '', $product['name'] );?>",
|
||||
quantity: <?= (int)$product['quantity'];?>,
|
||||
price: <?= ((float)$product['price_brutto_promo'] > 0 && (float)$product['price_brutto_promo'] < (float)$product['price_brutto']) ? \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto_promo'] ) : \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto'] );?>,
|
||||
google_business_vertical: "retail"
|
||||
}<? if ( $product != end( $this -> order['products'] ) ) echo ',';?>
|
||||
<? endforeach;?>
|
||||
]
|
||||
|
||||
@@ -275,12 +275,15 @@
|
||||
dataLayer.push({
|
||||
event: "view_item",
|
||||
ecommerce: {
|
||||
currency: "PLN",
|
||||
value: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||
items: [
|
||||
{
|
||||
item_id: "<?= $this -> product['id'];?>",
|
||||
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
||||
price: '<? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>',
|
||||
quantity: 1
|
||||
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||
quantity: 1,
|
||||
google_business_vertical: "retail"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -617,7 +620,8 @@
|
||||
item_id: "<?= $this -> product['id'];?>",
|
||||
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
||||
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||
quantity: quantity
|
||||
quantity: parseInt(quantity),
|
||||
google_business_vertical: "retail"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user