Just wondering if there is a way that I can add discounts to the shopping cart in Opencart.
Basically im wanting customers to be able to select an option, i,e size, then add bulk amounts to the shopping cart. This would then add say 1000 of this item directly to the shopping cart. Im trying to get something like this:
Buy 1000 or more for only £5.00 per unit [Add to cart]
Buy 2000 or more for only £4.50 per unit [Add to cart]
Here is my code so far, unfortunatly Im not sure how to get this working correctly so any help would be great.
Thanks!
<?php if ($discounts) { ?>
<br />
<div class="discount">
<?php foreach ($discounts as $discount) { ?>
<div class="discount-item">
<h3>Buy <?php echo $discount['quantity']; ?> or more for only <?php echo $discount['price']; ?></h3>
<a onClick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><?php echo $button_cart; ?></a>
</div>
<?php } ?>
</div>
<?php } ?>
It's unclear exactly what you're asking for. But if it's any help, the addToCart method that comes with the default template accepts an optional second field, which is the quantity. So you could do:
<a onClick="addToCart('<?php echo $product['product_id']; ?>', <?php echo $discount['quantity']; ?>);" class="button"><?php echo $button_cart; ?></a>
Edit for items with options:
I'll assume you're on the product page, as you need to select the options somehow... now we could clone the whole function that submits the data to the cart. But I think this is easier to manage:
First, change the link to look like this:
<a class="buy-bulk" data-quantity="<?php echo $discount['quantity']; ?>" class="button"><?php echo $button_cart; ?></a>
Then add the following near the bottom:
<script type="text/javascript">
$(document).ready(function() {
$('.buy-bulk').on('click', function() {
var quantity = $(this).data('quantity');
// change the quantity
$('input[name="quantity"]').val(quantity);
// simulate a click on the "add to cart button"
$('#button-cart').trigger('click');
})
});
</script>
NOTE: untested! :)
Related
This is my first time ever using isotope. So, I create the isotope instance inside of my document.ready function like so:
var grid = $('.headshots-list');
grid.isotope({
// options
itemSelector: '.headshots-list-item-alt',
layoutMode: 'fitRows',
sortBy: '[data-number]'
});
Then I set the values of each element in my grid layout including setting the data-number attribute.
$("#headshot_" + $(this).val()).attr('data-number', 2); // Users who are not chairpersons
$("#headshot_" + $(this).val()).attr('data-number', 1); // Users who are chairpersons
Then I try to sort the grid. Currently, I am using the setTimeout only because I was testing to see if maybe I had a race condition but it made no difference. The grid does not order itself in the way that I am expecting so that the user with data-number 1 will show before all other users. These attributes are being set. I have viewed the elements in dev tools to be sure.
As I mentioned earlier, this is the first time I have ever used isotope so not sure what I am doing wrong. Any pointers in the right direction will be greatly appreciated.
As requested below, this is the HTML where I build out the li that goes with this.
<li id="headshot_<?php echo $user->ID; ?>"
data-number = "1" class="headshots-list-item-alt js-headshot <?php echo $user_terms_classes . ' ' . $board_status . ' ' . $number; ?>"
data-toggle="modal"
data-target="#memberInfo_<?php echo $member_id; ?>">
<div class="headshot-list-item-inner">
<div class="headshot-list-photo">
<?php //suppress photo until they come in
?>
<?php if ($photo_id): ?>
<?php // echo wp_get_attachment_image( $photo_id, 'Avatar' ); ?>
<?php else: ?>
<?php // echo '<img src="https:somedomain.com/imgs/user_img.jpg"/>'; ?>
<?php endif; ?>
</div>
<h4 class="no-margin">
<?php echo $name; ?>
<input type="hidden" class="user_id" value="<?php echo $user->ID; ?>">
<span style="font-size:14px; display: block; position: relative; width: 100%;"
class="chair_designation" id="chair_designation_<?php echo $user->ID ?>">
</span>
</h4>
<p class="no-margin"><?php echo $title; ?></p>
<span class="headshot-list-item-tag">View Bio</span>
</div>
</li>
I've been able to get my arrays working to echo text from a database in HTML. Fine. However, I now want to send this text to another page onClick (JQuery or JavaScript). So here is what I already have (I know it's not sending anything, but this is not the problem right now) :
PHP
$h = "SELECT * FROM table";
$h=$pdo->prepare($h);
$h->execute();
$i=1;
while ($row = $h->fetch()) {
$text[$i] = $row['content'];
$id[$i] = $row['id'];
$i++;
}
HTML
<h1 id="<?php echo $id[0]; ?>" onClick="edit(this)"><?php echo $text[0]; ?>
</h1>
<h2 id="<?php echo $id[1]; ?>" onClick="edit(this)"><?php echo $text[1]; ?></h2>
<p id="<?php echo $id[2]; ?>" onClick="edit(this)"><?php echo $text[2]; ?></p>
JavaScript
function edit(element) {
alert(element.id);
}
So, this gives me the "id" of the content in the database. However, I'd like to know if there is a way to get this information without having the "id" in the HTML tags, a way to click on the text and have the number that is inside the square brackets.
Example : you click on the text inside the "h1" tag and a pop up tells you what is the number in <?php echo $text[2]; ?>. In this case, I would like the number 2 to show up in the alert box, without using id="<?php echo $id[2]; ?>".
I have an codeigniter based website. I am trying to output user information to print out a shipping label for them. Everything works okay however the information that is displayed in the new pop out window is not in the right format and one of the parameters is coming up as undefined. The code I am using is below:
from admin_controller.php
public function address(){
$data['Address']=$this->input->get("Address");
$data['firstname']=$this->input->get("firstname");
$data['lastname']=$this->input->get("lastname");
$data['address1']=$this->input->get("address1");
$data['address2']=$this->input->get("address2");
$data['suburb']=$this->input->get("suburb");
$data['state']=$this->input->get("state");
$data['postcode']=$this->input->get("postcode");
$data['mobile']=$this->input->get("mobile");
$this->load->view('admin/address',$data);
}
Code related to the button itself
<a class="btn btn-primary" href="#" onClick="Address('<?php echo $order->firstname ?>','<?php echo $order->lastname ?>','<?php echo $order->address1 ?>','<?php echo $order->address2 ?>','<?php echo $order->suburb ?>','<?php echo $order->state ?>','<?php echo $order->postcode ?>','<?php echo $order->mobile ?>')"> Label </a>
The Script
<script>
function Address(val,firstname,lastname,address1,address2,suburb,state,postcode,mobile){
window.open("<?php echo base_url();?>admin_controller/address?Address="+val+"&firstname="+firstname+"&lastname="+lastname+"&address1="+address1+"&address2="+address2+"&suburb="+suburb+"&state="+state+"&postcode="+postcode+"&mobile="+mobile+"",null,"width=800,height=400,left=100,top=100");
}
</script>
You are not passing a value for parameter val to your Javascript function.
onClick="Address('<?php echo $order->firstname ?>'
should be something like:
onClick="Address('theValue', '<?php echo $order->firstname ?>'
I am stuck in a place in Yii. I have two drop Down box, second is dependent on the first. In this first drop Down, I have many options. By referring to these options, I must decide whether the second box must be a drop Down or a text Field.
I have uploaded My code here. Please help me solving this.
Thanks in advance.
My View:
<td>
<?php echo $form->labelEx($model,'cm_classification_id'); ?>
<?php echo $form->dropDownList($model,'cm_classification_id', CHtml::listData(masterClassification::model()->findAll(array('order' => 'cm_classification_id ASC', 'condition'=>'cm_classification_type=:type', 'params'=>array('type'=>'initiate'))), 'cm_classification_id', 'cm_classification_name'), array('empty'=>'Select classification')); ?>
<?php echo $form->error($model,'cm_classification_id'); ?>
</td>
<td>
<label>Change Description <span class="required" id="desc_req_note" style="display:none;">*</span></label>
<?php echo $form->dropDownList($model,'cm_description',array(),array('empty'=>'Select Change Description')); ?>
<?php echo $form->error($model,'cm_description'); ?>
</td>
based on the change classification, I must decide where Change Description must be a drop Down or a text field.
This must be done using Javascript.
Have you tried this -
Change the code to -
<label>Change Description <span class="required" id="desc_req_note" style="display:none;">*</span></label>
<span id="cm_desc_select" style="display:none;"><?php echo $form->dropDownList($model, 'cm_description', array(), array('empty'=>'Select Change Description')); ?></span>
<span id="cm_desc_input" style="display:none;"><?php echo $form->textField($model,'cm_description'); ?></span>
<?php echo $form->error($model,'cm_description'); ?>
2.
$('#cm_classification_id').change(function() {
var val = $(this).val();
var cm_desc_select_elem = $('#cm_desc_select');
var cm_desc_input_elem = $('#cm_desc_input');
if(val === COMPARE_WITH_YOUR_VALUE) {
$(cm_desc_select_elem).show();
} else {
$(cm_desc_input_elem).show();
}
});
I hope is helps for a quick fix.
http://bit.ly/bsydBA
I've widened the product slider displaying boots to be full page width but I'm not seeing how to expand the number of products being displayed neither vía CSS or the code in featured.phtml (below). I also haven't found anything in the admin which would let me set any parameters.
The site just came to me after a variety of prior developers got under the hood so I'm just wrapping my head around any changes made to core files (yes, they didn't use /app/code/local/).
Has anyone worked with theme or see where I might be able to make the required adjustment?
Thanks in advance.
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
<?php echo $this->__('There are no products matching the selection. Please provide a category ID.') ?>
</div>
<?php else: ?>
<?php // Grid Mode ?>
<ul id="featured" class="jcarousel-skin-tango">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if($i++%4==0): ?>
<?php endif ?>
<li><a class="preview" rel="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300, 300); ?>" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(105, 105); ?>" width="105" height="105" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
</a> </li>
<?php if ($i%4==0 && $i!=$_collectionSize): ?>
<?php endif ?>
<?php endforeach ?>
I solved the issue. Turns out the site was using GTSpeed to minify the JS and CSS and cache them so the changes that I made in Firebug just didn't appear.
Once I figured this out and disabled it was a snap, just needed to change
.jcarousel-skin-tango .jcarousel-container-horizontal for the outer container
.jcarousel-skin-tango .jcarousel-clip-horizontal for the inner container