Jump to content
Sign in to follow this  
Katerina28

Выбор опции по умолчанию

Recommended Posts

Здравствуйте! Столкнулась с php впервые в жизни, только начинаю вникать, а правку необходимо сделать сейчас, поэтому прошу у вас помощи! 
Необходимо сделать так, чтобы при добавлении товара в корзину опция автоматически выбиралась (любая! лучше всего первая). В интернете есть решения на стандартную тематику, у меня же шаблон Shop-Store 2.

Вот кусок кода, связанный с этим моментом(если я ничего не путаю):

<?php if ($option['type'] == 'radio') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>">
	<div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
		<b class="req-star"><?php echo $option['name']; ?>:</b><br />
		<?php foreach ($option['product_option_value'] as $option_value) { ?>
		<?php if ($option_value['quantity_status']) { ?>
		<?php if ($option_value['image']) { ?>
		<div class="radio">
			<label class="not-selected-img optimid-<?php echo $option['option_id'];?>">
			<?php if (isset($images_by_options_data['status']) && $images_by_options_data['status']) { ?>
			<input onchange="update_prices_opt();" type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" class="none"/>
			<?php } else { ?>
			<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" class="none"/>
			<?php } ?>
			<img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" class="img-thumbnail" data-toggle="tooltip" data-trigger="hover" title="<?php echo $option['name']; ?> <?php echo $option_value['name']." "; if ($option_value['price']) { ?><?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?><?php } ?>"/>
			</label>
		</div>
		<?php } else { ?>
		<?php if (isset($images_by_options_data['status']) && $images_by_options_data['status']) { ?>
		<input onchange="update_prices_opt();" type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" class="none" />
		<?php } else { ?>
		<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" class="none" />
		<?php } ?>
		<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>" data-toggle="tooltip" data-trigger="hover" title="<?php echo $option['name']; ?> <?php echo $option_value['name']." "; if ($option_value['price']) { ?><?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?><?php } ?>" class="not-selected optid-<?php echo $option['option_id'];?>"><?php echo $option_value['name']; ?>
		</label>
		<?php } ?>
		<?php } else { ?>
		<?php if ($option_value['image']) { ?>
		<div class="radio">
			<label class="not-selected-img optimid-<?php echo $option['option_id'];?>">
				<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" class="none" disabled/>
				<div class="disable-image-option" data-toggle="tooltip" data-trigger="hover click focus" title="<?php echo $product_na; ?>">
					<img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" data-toggle="tooltip" data-trigger="hover"  class="img-thumbnail"/>
				</div>
			</label>
		</div>
		<?php } else { ?>
		<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" class="none" disabled/>
		<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>" data-toggle="tooltip" data-trigger="hover" title="<?php echo $product_na; ?>" class="not-selected optid-<?php echo $option['option_id'];?>"><?php echo $option_value['name']; ?>
		</label>
		<?php } ?>
		<?php } ?>
		<?php } ?>
		<div class="clearfix"></div>
	</div>
</div>
<script>
	$(document).ready(function() {
		   $('label.optid-<?php echo $option['option_id'];?>').click(function(){
	       if ($(this).prev().is('input:disabled')) {
	        $('label.selected').removeClass('selected').addClass('not-selected');
	        $(this).css({
	          'opacity': 0.5,
	          'cursor': 'default'
	        });
	       } else {
	        $('label.optid-<?php echo $option['option_id'];?>').removeClass('selected').addClass('not-selected');
	        $(this).removeClass('not-selected').addClass('selected');
	       }
		   });
	   $('label.optimid-<?php echo $option['option_id'];?>').click(function(){
	     if ($(this).find('input').is(':disabled')) {
	       $('label.optimid-<?php echo $option['option_id'];?>').removeClass('selected-img').addClass('not-selected-img');
	     } else {
	       $('label.optimid-<?php echo $option['option_id'];?>').removeClass('selected-img').addClass('not-selected-img');
	       $(this).removeClass('not-selected-img').addClass('selected-img');
	     }
	   });
	});

</script>
<?php } ?>


Буду благодарна за любые подсказки!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
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.