Jump to content

Recommended Posts

Привет.
У меня в Окстор 2.3 есть такой скрипт:
<script>
$( "input.form-control" ).blur(function() {var min=+($(this).attr("placeholder"));var val = +($(this).val());var ost= val % min;if(ost < min/2 && val != ost)    $(this).val(val - ost); else $(this).val(val - ost + min);    });
</script>

 

В шаблоне:
<input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>

 

На Опенкарт 1.5.6
Шаблон:
<input type="text" value="<?php echo $product['minimum']; ?>" class="item-<?php echo $product['product_id']; ?>

 

 
Подскажите, пожалуйста, как внедрить скрипт из 2.3 в 1.5.6? Или просто подскажите скрипт для 1.5.6, чтобы при вводе не кратного количества, оно менялось на кратное.
Спасибо.

Share this post


Link to post
Share on other sites

Попробую упростить вопрос :)

Сейчас у меня при вводе в поле количества числа не кратного минимуму, оно меняется на кратное.

Но теперь товары все (не зависимо от введенного числа) попадают в корзину по 1 штучке.

Спойлер

 <div class="product-block clearfix" itemtype="http://schema.org/Product" itemscope>

		<div class="image">
<?php if ($product['d']) { ?>
                    <br />
                    <div class="discount" style="
    position: absolute;
    display: flex;
    bottom: 0%;
    background: gold;
    color: red;
    font-family: serif;
    border: solid 2px;
    font-size: large;
    border-radius: 5%;
    padding: 1px 3px 1px 2px;
">
                      <?php foreach ($product['d'] as $discount) { ?>
                      <?php echo $text_opt; ?><?php echo $discount['quantity']; echo $text_po; echo $this->currency->format($this->tax->calculate($discount['price'], $product['tax_class_id'], $this->config->get('config_tax'))); ?><br />
                      <?php } ?>
                    </div>
                <?php } ?>
			<a class="img" title="<?php echo $product['name']; ?>" href="<?php echo $product['href']; ?>">
				<img class="img-responsive" src="<?php echo $product['thumb']; ?>"  width="<?php echo $product['thumbw']; ?>" height="<?php echo $product['thumbh']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" />
            </a>

            <?php if ( isset($quickview) && $quickview ) { ?>
                <a class="pav-colorbox btn btn-outline" href="<?php echo $this->url->link("themecontrol/product",'product_id='.$product['product_id'] );?>" title="<?php echo $this->language->get('quick_view'); ?>"><buttom type="submit">Быстрый просмотр</buttom></a>
            <?php } ?>
			<?php if( isset($categoryPzoom) && $categoryPzoom ) { $zimage = str_replace( "cache/","", preg_replace("#-\d+x\d+#", "",  $product['thumb'] ));  ?>
				<a href="<?php echo $zimage;?>" class="btn btn-outline colorbox product-zoom cboxElement" title="<?php echo $product['name']; ?>"><i class="fa fa-search-plus"></i></a>
			<?php } ?>
		</div>
					 
	<div class="product-meta">		  
		<div class="left">
            <div class="review clearfix">
                <h3 class="name" itemprop="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?><?php if ($product['isbn'] != '' ) { ?> <span style="color: red;">(<?php echo $product['isbn']; ?>)</span><?php } ?></a></h3>

                <?php if ( isset($product['rating']) && $product['rating'] ) { ?>
                <div class="rating" style="position: absolute; top: -15px;"><img src="catalog/view/theme/<?php echo $this->config->get('config_template');?>/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['rating']; ?>"></div>
				<div style="float: left; font-size: 11px; color: #02A5E5; height: 25px;">Наличие: <?php echo $product['stock']; ?> шт.<?php if ($product['ean'] > 0 ) { ?><hr style="margin: 0;">в упаковке <?php echo $product['ean']; ?> шт.<?php } ?></div>
				<div class="wishlist" style="float: right; padding-left: 5px;">
					<a onclick="addToWishList('<?php echo $product['product_id']; ?>');" title="<?php echo $this->language->get("button_wishlist"); ?>" class="btn btn-outline">
				 		<i class="fa fa-heart"></i>
						<span><?php echo $this->language->get("button_wishlist"); ?></span>
					</a>	
				</div>	
				<div class="compare" style="float: right;">			
					<a class="btn btn-outline" onclick="addToCompare('<?php echo $product['product_id']; ?>');" title="<?php echo $this->language->get("button_compare"); ?>">
						<i class="fa fa-refresh"></i>
						<span><?php echo $this->language->get("button_compare"); ?></span>
					</a>	
				</div>
                <?php } else { ?>
				<div style="float: left; font-size: 11px; color: #02A5E5; height: 25px;">Наличие: <?php echo $product['stock']; ?> шт.<?php if ($product['ean'] > 0 ) { ?><hr style="margin: 0;">в упаковке <?php echo $product['ean']; ?> шт.<?php } ?></div>
				<div class="wishlist" style="float: right; padding-left: 5px;">
					<a onclick="addToWishList('<?php echo $product['product_id']; ?>');" title="<?php echo $this->language->get("button_wishlist"); ?>" class="btn btn-outline">
				 		<i class="fa fa-heart"></i>
						<span><?php echo $this->language->get("button_wishlist"); ?></span>
					</a>	
				</div>	
				<div class="compare" style="float: right;">			
					<a class="btn btn-outline" onclick="addToCompare('<?php echo $product['product_id']; ?>');" title="<?php echo $this->language->get("button_compare"); ?>">
						<i class="fa fa-refresh"></i>
						<span><?php echo $this->language->get("button_compare"); ?></span>
					</a>	
				</div>
                <?php } ?>
            </div>
			<!-- <div><span style="color: red;"><?php echo $product['jan']; ?></span></div> -->
			<?php if ($product['price']) { ?>
			<div class="price" itemtype="http://schema.org/Offer" itemscope>
			<?php if ($product['stock'] >= 1) { ?>
				<?php if ((!$product['special'])) {  ?>
				<div class="cart" style="text-align: right;">
				
					
					<script type="text/javascript"><!--
function addQtyToCart(product_id) {
var qty = $('.item-' + product_id).val();
if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
qty = 1;
}
addToCart(product_id, qty);
}
//--></script>
					<?php if ($this->customer->isLogged()) { ?>
					<?php if ($product['minimum'] > 1) { ?>
							<span style="color:red;">Отпускается кратно кол-ву в уп. <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>
						<?php } else { ?>
					<span style="color: black;">Укажите кол-во: <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>
					<?php } ?>
					<?php if ($this->customer->getCustomerGroupId() == $this->config->get('nomer_group') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_2') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_3') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_4') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_5') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_6') || $this->customer->getCustomerGroupId() == $this->config->get('nomer_group_7')) { ?>
					<span class="price-old">
					<?php if ($product['jan'] != null ) { ?>
					<div class="razdel" style="color:red;"><?php echo $product['jan']; ?></div>
					<?php } else { ?>
					<div class="razdel">Крупный опт</div>
					<?php } ?>
					<?php echo $product['price']; ?><input type="button" value="Купить оптом" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="button knopka-tov" /></span>
					<?php } else { ?>
					<span class="price-old"><div class="bord"><div class="razdel">Крупный опт</div><?php echo $product['price']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Опт</div><?php echo $product['price_2']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Мелкий опт</div><?php echo $product['price_3']; ?></div>
					<?php if ($product['cart'] == true) { ?>
					<input type="button" value="<?php echo (!$product['cart']) ? '' : 'Уже в корзине'; ?>" type="button" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="button knopka-korzina" /></span>
					<?php } else { ?>
					<input type="button" value="<?php echo $button_cart ?>" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="button knopka-tov" /></span>
					<?php } ?>
					<?php } ?>
					<?php } else { ?>
					
					<div class="cart" style="text-align: right;">
									<script type="text/javascript"><!--
function addQtyToCart(product_id) {
var qty = $('.item-' + product_id).val();
if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
qty = 1;
}
addToCart(product_id, qty);
}
//--></script>
					<?php if ($product['minimum'] > 1) { ?>
							<span style="color:red;">Отпускается кратно кол-ву в уп. <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>
						<?php } else { ?>
					<span style="color: black;">Укажите кол-во: <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>
					<?php } ?>

					<span class="price-new" style="display:none;"><?php echo $product['special']; ?>

					<?php if( !isset($listingConfig['catalog_mode']) || !$listingConfig['catalog_mode'] ) { ?>

          <button onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="btn <?php echo $category['category_id']; ?> btn-outline-inverse btn-variant roznica">
						<span><?php echo $this->language->get("button_cart"); ?></span>
					</button>
				
				
				<?php } ?>
					
					</span>
					<span class="price-old"><div class="bord"><div class="razdel">Крупный опт</div><?php echo $product['price']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Опт</div><?php echo $product['price_2']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Мелкий опт</div><?php echo $product['price_3']; ?></div><a class="btn btn-outline-inverse knopka-tov" href="/index.php?route=account/simpleregister"><span><?php echo (!$product['cart']) ? $button_cart : ' Куплено'; ?></span></a></span> 
					</div>
			 
					<?php if( preg_match( '#(\d+).?(\d+)#',  $product['special'], $p ) ) { ?> 
					<meta content="<?php echo $p[0]; ?>" itemprop="price">
					<?php } ?>
					
					<?php } ?>
					
					</div>
					<?php if( preg_match( '#(\d+).?(\d+)#',  $product['price'], $p ) ) { ?> 
					<meta content="<?php echo $p[0]; ?>" itemprop="price">
					<?php } ?>
				<?php } else { ?>
				<div class="cart" style="text-align: right;">
									<script type="text/javascript"><!--
function addQtyToCart(product_id) {
var qty = $('.item-' + product_id).val();
if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
qty = 1;
}
addToCart(product_id, qty);
}
//--></script>
					<?php if ($product['minimum'] > 1) { ?>
							<span style="color:red;">Отпускается кратно кол-ву в уп. <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>
						<?php } else { ?>
					<span style="color: black;">Укажите кол-во: <input type="text" class="form-control" placeholder="<?php echo $product['minimum']; ?><?php echo $product_id; ?>"style="width:20%;margin: 0px;display: inline-flex;"></span>
					<?php } ?>

					<span class="price-new" style="display:none;"><?php echo $product['special']; ?>

					<?php if( !isset($listingConfig['catalog_mode']) || !$listingConfig['catalog_mode'] ) { ?>

          <button onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="btn <?php echo $category['category_id']; ?> btn-outline-inverse btn-variant roznica">
						<span><?php echo $this->language->get("button_cart"); ?></span>
					</button>
				
				
				<?php } ?>
					
					</span>
					<span class="price-old"><div class="bord"><div class="razdel">Крупный опт</div><?php echo $product['price']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Опт</div><?php echo $product['price_2']; ?></div>
					<span class="price-old"><div class="bord"><div class="razdel">Мелкий опт</div><?php echo $product['price_3']; ?></div><a class="btn btn-outline-inverse knopka-tov" href="/index.php?route=account/simpleregister"><span><?php echo (!$product['cart']) ? $button_cart : 'Куплено'; ?></span></a></span> 
					</div>
			 
					<?php if( preg_match( '#(\d+).?(\d+)#',  $product['special'], $p ) ) { ?> 
					<meta content="<?php echo $p[0]; ?>" itemprop="price">
					<?php } ?>				

				<?php } ?>				
				<?php } else { ?>
				<div class="cart" style="text-align: right;">
          <button class="knopka-tov-2">
						<span>Нет в наличии</span>
					</button>
					</div>
<?php } ?>				
				<?php if ( isset($product['tax']) && $product['tax']) { ?>	        
					<span class="price-tax"><?php echo $this->language->get('text_tax'); ?> <?php echo $product['tax']; ?></span>
				<?php } ?>

				<meta content="<?php echo $this->currency->getCode(); ?>" itemprop="priceCurrency">
			</div>
			<?php } ?>
			<?php if( isset($product['description']) ){ ?> 
			<p class="description" itemprop="description"><?php echo utf8_substr( strip_tags($product['description']),0,220);?>...</p>
			<?php } ?>	
		</div>		
	</div>		 
</div>
<script>
$( "input.form-control" ).blur(function() {var min=+($(this).attr("placeholder"));var val = +($(this).val());var ost= val % min;if(ost < min/2 && val != ost)	 $(this).val(val - ost); else $(this).val(val - ost + min);	});
</script>

 

 

Подскажите, пожалуйста, что не так?

Спасибо

Share this post


Link to post
Share on other sites

Я понимаю, что нужно поправить или это:

<script type="text/javascript"><!--
function addQtyToCart(product_id) {
var qty = $('.item-' + product_id).val();
if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
qty = 1;
}
addToCart(product_id, qty);
}
//--></script>

или это:

<script>
$( "input.form-control" ).blur(function() {var min=+($(this).attr("placeholder"));var val = +($(this).val());var ost= val % min;if(ost < min/2 && val != ost)	 $(this).val(val - ost); else $(this).val(val - ost + min);	});
</script>

чтобы заработало в связке с:

<span style="color:red;">Отпускается кратно кол-ву в уп. <input type="text" value="<?php echo $product['minimum']; ?>" class="item-<?php echo $product['product_id']; ?>"style="width: 20%;margin: 0px;display: inline-flex;"></span>

Я в скриптах не понимаю. Помогите.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.