PHP Codeigniter - How to set value to create database by option select - php

I try to make a shipping method using Rajaongkir API, but I need to add some data to my database that contain the shipping cost <?php echo $data['rajaongkir']['results'][$k]['costs'][$l]['cost'][0]['value'] ?>
but, it is always show an"0" in my database
this is my view
<?php echo form_open('orders/proceed'); ?>
<select class="form-control">
<option name="ongkir" selected="" disabled="">Pilih Layanan</option>
<?php
for ($l=0; $l < count($data['rajaongkir']['results'][$k]['costs']); $l++) {
?>
<?php echo "<option value='".$data['rajaongkir']['results'][$k]['costs'][$l]['cost'][0]['value']."'>" ?>
Layanan <?php echo $data['rajaongkir']['results'][$k]['costs'][$l]['service'] ?> |
<?php echo $data['rajaongkir']['results'][$k]['costs'][$l]['cost'][0]['etd'] ?> Hari | Rp.
<?php echo $data['rajaongkir']['results'][$k]['costs'][$l]['cost'][0]['value'] ?>
<?php "</option>"; ?>
<?php
}
?>
</select>
and this is the controller
$carts = $this->cart->contents();
$ongkir = $this->input->post('ongkir');
foreach ($carts as $item) {
$product = $this->Product->getProductByCode($item['id']);
$detail['code'] = $item['id'];
$detail['name'] = $item['name'];
$detail['price'] = $item['price'];
$detail['qty'] = $item['qty'];
$detail['discount_percent'] = $item['options']['discount_percent'];
$detail['net_price'] = $product['net_price'];
$detail['weight'] = $item['options']['weight'];
$detail['order_id'] = $orderId;
$detail['ongkir'] = $ongkir;
$this->Order_detail->create($detail);
}
this is the screenshot
I cannot add the shipping cost to my value.
How to resolve it and and those shipping cost value to my database?

Related

WordPress: How to order child pages in a select menu?

I have a select box, which allows you to navigate between parent pages and their children, they are given a specific order, in order to display them in a certain way on the website.
I believe that the line of code that interest you is perhaps this one
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0");
The full code is below. You can see that the order of the pages on the site is different than the order of the pages in the select menu, that is because wordpress sorts per order, my pages are sorted alphabetically. How to sort them by order, so that what you see on the website matches the select box?
<?php
// determine parent of current page
if ($post->post_parent)
{
$ancestors = get_post_ancestors($post->ID);
$parent = $ancestors[count($ancestors) - 1];
}
else
{
$parent = $post->ID;
}
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0");
?>
<div id="info-select-wrap" class="single-france-select">
<select id="info-select"class="fr-select" >
<?php
if (get_the_ID() == $parent->ID): ?>
<option value="<?php
echo get_the_permalink($parent->ID); ?>" selected>  <?php
echo get_the_title($parent->ID); ?></option>
<?php
else: ?>
<option value="<?php
echo get_the_permalink($parent); ?>">  <?php
echo get_the_title($parent); ?></option>
<?php
endif;
foreach($children as $child):
if (has_children($child))
{
if (get_the_ID() == $child->ID)
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>" selected>  <?php
echo get_the_title($child->ID); ?></option>
<?php
}
else
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>"> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
}
else
{
if (get_the_ID() == $child->ID)
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>" selected>  <?php
echo get_the_title($child->ID); ?></option>
<?php
}
else
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>"> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
}
endforeach; ?>
</select>
</div>
I tried
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0&orderby='menu_order'&order='ASC'");
Didn't solve it.
Issue solved by adding sort_column=menu_order
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0&sort_column=menu_order");
Just a quick note, &echo=0 is useless, you can remove it.

adding category and its subcategories in html select

i am trying to add father categories then its subcategories as options in select , so i did the following
<select class="form-control" name="select">
<?php foreach($father as $father) : ?>
<option value="<?php echo $father->id; ?>">
*Category: <?php echo $father->name." :-"; ?>
</option><?php foreach($child as $child) : ?><?php if($child->category_id==$father->id){?>
<option value="<?php echo $child->id; ?>">
-Sub-Category: <?php echo $child->name; ?>
</option><?php } endforeach; ?><?php endforeach; ?>
</select>
here is my controller
public function addg()
{
$this->load->model('catagories_model');
$data['userdata'] = $this->session->all_userdata();
$data['father'] = $this->catagories_model->get_catagories();
$data['child'] = $this->catagories_model->get_catagories_child();
$this->load->view('catagories/grand/add', $data);
}
but it loops into the first father category and display its children and just displays the other father categories without going into the if statement what could be wrong ?
This line isn't doing anything:
<?php foreach($child as $child) : ?>
It should be:
<?php foreach($childs as $child) : ?>
Assuming $childs is the array where you're storing all the subcategories.

pagination not working properly in searching

I have created some code of searching and pagination in it. If a user wants to search using some industry then data is shown against it. But whenever he presses any option in the pagination then it shows all the data related to every industry. How can i show pagination related to search result. And if user has selected any industry then it should be selected if user move to page 2 or page 3 or any.
Code of page
<?php
$pd=(isset($script['details']) ? $script['details']:array()) ;
//jobs search and normal page view
$qstr=Querystring();
$obj_pagination = new Pagination();
$obj_pagination->limit = (($FP_LIMIT!="") ? $FP_LIMIT:10);
$pagid=1;
if(isset($qstr["page"])) {
$pagid=$qstr["page"];
}
$obj_pagination->page = $pagid;
$srcqry="";
$industry=0;
if(isset($_POST['industry'])){
if(isset($_POST['industry'])){
if($_POST['industry']!="0") {
$srcqry=$srcqry." AND j.industry ='".(int)$_POST['industry']."'";
$industry=(int)$_POST['industry'];
}
}
$nrs = $obj->query("SELECT * FROM jobs j WHERE j.status='1' ".$srcqry);
} else {
$nrs = $obj->query("SELECT * FROM jobs j WHERE j.status='1' ".$srcqry);
}
$tot_rec= count($nrs->rows);
$obj_pagination->total = $tot_rec;
$obj_pagination->url = "jobs?page={page}";
$num_pages = ceil($obj_pagination->total / $obj_pagination->limit);
$start = ($obj_pagination->page-1)*$obj_pagination->limit;
$end = $obj_pagination->limit;
$limit = "LIMIT $start,$end";
$check;
?>
<h3>Search</h3>
<form name="srchjobs" action="/jobs" method="post">
<div class="col1">
<select class="dropdown1 spacer_side" name="industry">
<option value="0">All Industries</option>
<?php $indrow=getAllIndustries();
if(count($indrow) > 0) {
foreach($indrow as $tr) {?>
<option value="<?php echo $tr['id']; ?>" <?php if($tr['id']==$industry) { ?> selected="selected"<?php } ?>><?php echo $tr['name']; ?></option>
<?php }
$check=$tr['name'];
}
?>
</select>
</div>
<button type='submit'>Search</button>
</form>
<?php
$indrow=getAllIndustries();
$sql="SELECT j.*,u.url FROM jobs as j, aliases as u WHERE j.status='1' ".$srcqry."
AND (j.id=u.slog_id AND u.slog='jobs') ORDER BY j.id DESC ".$limit;
$jresults = $obj->query($sql);
if($jresults->rows) {
foreach($jresults->rows as $j){
$empd=array();
$empd=getIndinfo($j['industry']);
$emplogo="/uploads/no-image.png";
?>
<img src="<?php echo $emplogo;?>" alt="dell1" height="66" width="66" />
<h5><?php echo $j['title']; ?></h5>
APPLY
<?php } ?>
<ul class="pagination">
<?php
$obj_pagination->text_next = ">";
$obj_pagination->text_prev = "<";
$obj_pagination->text_first = "«";
$obj_pagination->text_last = "»";
$obj_pagination->text = "Showing {start} to {end} of {total}";
echo $obj_pagination->render();
?></ul>
<?php } else { ?>
<span class="latest_job">No jobs Found</span>
<?php } ?>
querystring function code
function Querystring(){
$_G=array();
$REQUEST_URI = $_SERVER['REQUEST_URI'];
$REQUEST_URI_ARR = explode("?",$REQUEST_URI);
$REQUEST_URI_ARR_All = explode("&",$REQUEST_URI_ARR[1]);
foreach($REQUEST_URI_ARR_All as $key=>$val){
$gs = explode("=",$val);
if(isset($gs[0]) && isset($gs[1]))
$_G[$gs[0]] = urldecode($gs[1]);
}
return $_G;
}
Output your results in a table and just use a jquery enabled table class. That way pagination will be automatic. Ensure you have a tag as well.

Shopp plugin in wordpress -to display select box of shipping method

I'm new to WordPress and a very new to "shopp plugin",
I want to select box that displays shipping method
shopp('shipping', 'option-menu', 'difference=on');
This doesn't work. Please tell me in details about how to fetch this shipping method data using above code and where to look after the code for further changes to get the select box with details comes by OrderAmount-0, ItemQuantity-0 filling from [shipping menu] present in [system] side menu.
Try this code:
<?php if ( shopp('shipping', 'has-options') ): ?>
<?php while ( shopp('shipping','options')):
$selected = '';
if ( shopp('shipping','option-selected') )
$selected = ' selected="selected"';
$value = shopp('shipping','get-option-slug');
$name = shopp('shipping','get-option-name');
$cost = shopp('shipping','get-option-cost);
$delivery = shopp('shipping', 'get-option-delivery');
$label = $name.' &mdash '.$cost.' '.$delivery;
?>
<select name="shipmethod" class="shopp shipmethod">
<option value="<?php echo $value; ?>"<?php echo $selected; ?> ><?php echo $label; ?></option>
</select>
<?php endwhile; ?>
<?php endif; ?>

how to get cart values in codeigniter for paypal payment gateway

I am stuck on integrating paypal payment gateway on codeigniter
I am using the current library
https://github.com/romaldyminaya/ci_paypal
As the library contains only static values of the items , but i need to get the items that are coming from my cart, how can i get them to the $this->paypal->add('T-shirt',2.99,6);
my controller function:
public function do_purchase(){
$config['business'] = 'babar.seller#gmail.com';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'http://localhost/final-project/index.php/mysite/modify_payment';
$config['cancel_return'] = 'http://final-project/mysite/canceled.php';
$config['notify_url'] = 'process_payment.php'; //IPN Post
$config['production'] = FALSE; //Its false by default and will use sandbox
$config["invoice"] = random_string('numeric',8); //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',2.99,6); //First item
$this->paypal->add('Pants',40); //Second item
$this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code
$this->paypal->pay(); //Proccess the payment
}
public function modify_payment(){
$received_data = print_r($this->input->post(),TRUE);
echo "<pre>".$received_data."<pre>";
$this->load->view('mysite/modify_payment',$received_data);
}
public function cart()
{
$cart = $this->cart->contents();
//print_r($cart);
//die;
//$data['user_id']=$this->mainmodel->get_user_i($user_id);
$this->load->view('mysite/cart');
$this->load->view('mysite/include/footer');
}
cart view :
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td> <input name="qty[<?php echo $items['rowid'];?>]" id="qty" type="text" value="<?php echo $items['qty']?>" class="input" />
</td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
</p>
<?php endif; ?>
function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
$this->config['item_name_'.$this->item] = $item_name;
$this->config['amount_'.$this->item] = $item_amount;
$this->config['quantity_'.$this->item] = $item_qty;
$this->config['item_number_'.$this->item] = $item_number;
$this->item++;
}
What i did is had a paypal library class that handled the addition and just simply hard coded inn some products

Categories