Quantity is not updating in magento site - database

we have marketplace multi vendor/seller site. we gave an option for seller to update the product information through frontend.....
As it is marketplace site, we have many sellers.
seller A uploaded product A in frontend [quantity = 20 ]
if seller B have same product , he will assign the same product to his account [quantity = 5 ]
in backend it showing 20 + 5 = 25 quantity.
now the problem is when seller A update the quantity from 20 to 40, it showing 40 in frontend and once we refresh the page, it showing only 35. Means after refreshing it showing quantity of [ Seller A qty- Seller B qty ]
but it should show seller A Quantity.
Before It was working properly , later we did some code changes than we are facing this Problem.
before the qty textfield was looking like as in image :
once we click on "edit " button present in image, it looks like below image :
But we decided to display below image :
so we changed code to look like above image. Than this problem happened.
Before Code : [Everything was working fine ]
<td>
<?php
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId());
//Zend_Debug::dump($selllermpassignproduct,null,true);
$stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products);
$SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty();
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
?>
<span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) $SellerQty; ?></span>
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/>
<span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
<img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
</span>
<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
<br/>
<button id="update_button_<?php echo $products->getId(); ?>" class="buttons" onclick="updateField('<?php echo $products->getId(); ?>',<?php echo $assignqty;?>); return false;" style="display:none" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>
<button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;" style="display:none" >
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>
Script
function hideReset(product_id) {
var qtyId='#qty_'+ product_id;
var editLink="#edit_link_"+ product_id;
var updateButton="#update_button_"+ product_id;
var resetButton="#reset_button_"+ product_id;
$wk_jq(qtyId).hide();
$wk_jq(editLink).show();
$wk_jq(updateButton).hide();
$wk_jq(resetButton).hide();
}
function updateField(product_id,assignqty)
{
var qtyId = '#qty_'+ product_id;
var valueId = '#valueqty_'+ product_id;
var updatedqty = '#updatedqty_'+ product_id;
var editLink = "#edit_link_"+ product_id;
var updateButton = "#update_button_"+ product_id;
var resetButton = "#reset_button"+ product_id;
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';
$wk_jq(qtyId).toggle()
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(resetButton).show();
$qty = $wk_jq(qtyId).val();
jQuery(valueId).html($qty);
hideReset(product_id);
var tmpQty=assignqty+ parseInt($qty) ;
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, qty: tmpQty},
onComplete: function (transport) {
//alert(transport.responseText);
jQuery(priceId).val($price);
// $wk_jq(priceId).setValue($price);
jQuery(updatedqty).show().delay(2000).fadeOut();
$updateButton.prop('disabled', false);
// $wk_jq(qtyId).setValue($qty);
}
});
}
Present code
In the above code, we comment some lines and we replaced some codes as below.
commented code
<!-- <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?> -->
**script**
//$wk_jq(qtyId).toggle()
//$wk_jq(updateButton).show();
//hideReset(product_id);
//jQuery(updatedqty).show().delay(2000).fadeOut();
Replaced code 1 )
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock"
value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/>
to
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)"
name = "stock" class="ama1" value = "<?php echo (int) $SellerQty; ?>" />
Replaced code 2)
var tmpQty=assignqty+ parseInt($qty) ;
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, qty: tmpQty},
to
var tmpQty=parseInt(assignqty)+ parseInt($qty) ;
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, qty: $qty},

I found solution for 1st problem.
public function massupdatesellerproAction(){
if($this->getRequest()->isPost()){
if(!$this->_validateFormKey()){
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}
$ids= $this->getRequest()->getParam('product_mass_update');
$price= $this->getRequest()->getParam('price');
$special= $this->getRequest()->getParam('specialprice');
$i=1;
foreach ($ids as $key => $value) {
$i=$i+1;
$qty = $this->getRequest()->getParam('stock'.$i);
$product = Mage::getModel('catalog/product')->load($value);
$product->setPrice($price[$key]);
$product->setSpecialPrice($special[$key]);
//$product->setQty($qty);
$product->save();
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($value);
$stockItem->setData('manage_stock', 1);
$stockItem->setData('qty', $qty);
$stockItem->save();
}
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}}

Related

How to structure a multi array to process and sort WooCommerce Order Item data?

How can I extract details from an order into an array, while on the "Order Edit" page and then loop through them?
My array structure isn't correct as can't handle a 3rd item-detail. So each order item somehow needs to be placed into its own sub-array.
Then I want to be able to sort them on item-name and print them out with an echo.
How to achieve the correct array structure to input them and extract?
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'additional_admin_order_data_block_after_shipping_address', 100 );
function additional_admin_order_data_block_after_shipping_address(){
echo '</div><div class="order_data_column order_packing_column">
<h3>' . esc_html__( 'Packing Items', 'woocommerce' ) . '</h3>';
// here goes your code and content
//custom array to list products:
$products_array = array();
$product_tally = 0;
global $post; // <=== Alway at the beginning
// Get an instance of the WC_Order Object
$order = wc_get_order( $post->ID );
// let's decide what order item types we would like to get
$types = array( 'line_item');
// defaults to line_item which allows to get products from order
foreach( $order->get_items( $types ) as $item_id => $item ) {
// order ID
$item_order_id = $item->get_order_id();
// product only and no bundle 'summary' item
if( empty( $item['woosb_ids']) && $item->is_type( 'line_item' ) ) {
// order item name (product title, name of a shipping method or coupon code)
$item_name = $item->get_name();
if ( array_key_exists($item_name, $products_array)) {
$products_array[$item_name] += $item['qty'];
} else {
$products_array[$item_name] = $item['qty'];
}
$product_tally = $product_tally + $item->get_quantity();
}
}
arsort($products_array);
echo '<div class="woocommerce_order_items" id="packing-table">
<div class="thead">
<div class="tr">
<div class="item sortable">Product</div>
<div class="quantity sortable">Qty</div>
</div>
</div>
<div class="tbody" id="order_line_items">';
//display list:
foreach ($products_array as $title => $quantity) {
echo '<div class="lineitem">
<div class="item">';
echo $title.'</div>
<div class="quantity">'.$quantity.'</div>
</div>';
}
echo '<div class="lineitem tally">
<div class="item">Tally of Items</div>
<div class="quantity">'.$product_tally.'</div>
</div>';
echo '</div>
</div>';
}

implode function not working in codeigniter

I want to store a checkbox array value by using implode function.when i stored,the database table value as Array (not a integer value show only array)
This is my view file:
<div class="col-sm-12">
<div>
<label class="form-control-label">Select Asset Type</label><br>
<div class="border-checkbox-section">
<div class="border-checkbox-group border-checkbox-group-primary">
<?php $b=0; foreach($assettype as $assettype_info){ $b++;?>
<input type="checkbox" name="assettype_name[]" class="border-checkbox" value="<?php echo $assettype_info->assettype_name; ?>" id="checkbox<?php echo $b;?>">
<label class="border-checkbox-label" for="checkbox<?php echo $b;?>"><?php echo $assettype_info->assettype_name; ?></label>
<?php } ?>
</div>
</div>
</div>
My Controller:
public function insertassetassign()
{
$employee=$_POST['employee'];
$assettype_name = implode(", ", $_POST['assettype_name']) ;
$assign_date = date("Y-m-d",strtotime($_POST['assign_date']));
$_POST['assetassign_status']='1';
$joinon=date('Y-m-d');
$result = $this->insert->insertrecord('assetassign');
if($result)
{
redirect('assets/assetassignment', 'refresh');
}
}
My Model :
Public function insertrecord($Table)
{
$Inputs=$_POST;
$Inputs["joinon"]=date("Y-m-d");
$Keys=array();
$Values=array();
foreach($Inputs as $Inp_key=>$inp_value)
{
if($Inp_key!="submit" && $Inp_key!="PHPSESSID")
{
$Keys[]= $Inp_key;
$Values[]= "'".$inp_value."'";
}
}
$keys=implode(',',$Keys);
$values=implode(',',$Values);
$qry="insert into ".$Table."(".$keys.") values(".$values.")";
$ack=$this->db->query($qry);
if($ack) return true; else return false;
}
I expected to store a array value as id with comma
DB shows as :
Db shows as
modified in controller to get the answer.
public function insertassetassign()
{
$employee=$_POST['employee'];
$assettype_name = implode(",",$_POST['assettype_name']) ;
$_POST['assettype_name'] = $assettype_name;
$assign_date = date("Y-m-d",strtotime($_POST['assign_date']));
$_POST['assetassign_status']='1';
$joinon=date('Y-m-d');
$result = $this->insert->insertrecord('assetassign');
if($result)
{
redirect('assets/assetassignment', 'refresh');
}
}

how to upload image to folder and path ot db in cakephp controller

i have written code in controller to move the uploaded file to folder ,but it was not working ,my code is
$this->layout = "ajax";
if($this->request->data){
$postArr = $this->request->data;
$a = $postArr['image'];
$ext = substr(strtolower(strrchr($a, '.')), 1); //get the extension
$arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions
if(in_array($ext, $arr_ext))
{
//do the actual uploading of the file. First arg is the tmp name, second arg is
//where we are putting it
if(move_uploaded_file($a, WWW_ROOT . '/img/uploads/users' . $a)){
echo 'success';
$hai = 1;
}
else
{
echo 'failed';
$hai = 0;
}
}
.....
.....
......
$Curriculum = array();
$Curriculum['Shop']['image'] = $hai;
$this->Shop->save($Curriculum);
echo 0;
exit;
i think this line 'if(move_uploaded_file($a, WWW_ROOT . '/img/uploads/users' . $a)){ ... } was not working ,through this code i am able to store the '0 in my database i.e else part of the code.
how to move the uploaded image to folder and path to my database field..plz help me any one...!
my script code is
function addAdminList(){
var branchId = $('#branchId').val();
var branchName = $('#branchName').val();
var curiculumName = $('#curiculumName').val();
var owner = $('#owner').val();
var startdate = $('#startdate').val();
var phone = $('#phone').val();
var desc = $('#desc').val();
var address = $('#address').val();
var timings = $('#timings').val();
var image = $('#image').val();
if(!$("#addClsGrpFrm").validationEngine('validate')){
return false;
}
$('.overlay').show();
$.ajax({
url : '<?php echo BASE_PATH; ?>adminAjax/addAdminList',
type : 'POST',
data : {
branchId : branchId,
branchName : branchName,
curiculumName : curiculumName,
owner : owner,
startdate : startdate,
phone : phone,
desc : desc,
address : address,
timings : timings,
image : image
},
success : function(res){
$('.overlay').hide();
if(res == 0){
}
parent.$.colorbox.close();
oTable.fnDraw();
return false;
},
error : function(res){
alert('Server Error Occurred');
}
});
}
my form is
<form id="addClsGrpFrm" method="post" action="#" onsubmit="return disableFrmSubmit()">
<div class="flash_msg"><?php echo $this->Session->flash(); ?></div>
<input type="hidden" name="data[branch][id]" readonly id="branchId" value="0">
<div class="login-form">
<label>Shop Image</label>
<input type="file" id="image" data-prompt-position="topLeft:200" name="data[branch][image]" placeholder="" class="validate[required]" />
.....
</div>
<div class="login-form">
<input type="button" onclick="addAdminList()" class="login-btn" value="Submit">
</div>
<div class="clear"></div>
</form>
Some suggestions while submitting your form :
Use FormData when submitting your form rather than appending them one by one.
The extension extraction process that you are using in your controller may not save some files with "." in their filename.
I have created a test form for your knowledge.This is the form:
<form id="testForm" method="post" action="<?php echo 'http://localhost/blog/users/test'; ?>">
<input type="file" name="image" id="image">
<input type="submit" value="Submit">
</form>
You can use FormData like so:
$('#testForm').on('submit', function(event) {
event.preventDefault();
var form_data = new FormData($(this)[0]); // this will get all your form's inputs
$.ajax({
url:"<?php echo 'http://localhost/blog/users/test.json'; ?>", // you can use your form action URL here
type:'POST',
data:form_data,
processData: false,
contentType: false
});
});
and finally in your controller:
public function test() {
if ($this->request->is('post')) {
if (!empty($this->request->data['image']['tmp_name']) && is_uploaded_file($this->request->data['image']['tmp_name'])) {
$filename = basename($this->request->data['image']['name']);
$imagePath = WWW_ROOT . DS . 'documents' . DS . $filename; // save the file where you wish
move_uploaded_file(
$this->request->data['image']['tmp_name'],
$imagePath // save $imagePath in your database
);
}
}
}
You can use $imagePath to save in your database and as for your file extension process you can use this function as it will get the filetype even if the filename has a "dot" in it :
public function findFileTypeAndName($filename)
{
$split_point = '.';
$parts = explode($split_point, $filename);
$last = array_pop($parts);
$fileNameAndType = array(implode($split_point, $parts), $last);
return $fileNameAndType;
}
$this->layout = "ajax";
if($this->request->data){
$postArr = $this->request->data;
$a = $postArr['image'];
$ext = substr(strtolower(strrchr($a['name'], '.')), 1); //get the extension
$arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions
if(in_array($ext, $arr_ext))
{
//do the actual uploading of the file. First arg is the tmp name, second arg is
//where we are putting it
if(move_uploaded_file($a['tmp_name'], WWW_ROOT . '/img/uploads/users/' . basename($a['name']))){
echo 'success';
$hai = 1;
}
else
{
echo 'failed';
$hai = 0;
}
}
.....
.....
......
$Curriculum = array();
$Curriculum['Shop']['image'] = $hai;
$this->Shop->save($Curriculum);
echo 0;
exit;
The issue is just that you tried to pass the image array to strrchr($a) instead of strrchr($a['name']) at this point:
$ext = substr(strtolower(strrchr($a['name'], '.')), 1); //get the extension
Then you also tried to pass $a which is an array into move_uploaded_file($a,...).
Check my corrections for that part of the code...

getElementById from select box to text field

Im making a selectbox with the values from my DB, and I want to write the ID of the selected item to a textbox.
How can it be done? I have this code..
<form method="POST" action="" id="submitKon">
<fieldset>
<table class="opretTable" border="0">
<tr>
<td width="180" height="30"><label for="valgtkon" class="labelLeft">Vælg konkurrencetype</label></td>
<td><select id="valgtTitel" name="valgtTitel" onchange="run()">
<?php
$virksomhedsID = $_SESSION['virkID'];
$sql = "SELECT * FROM konkurrenceType ORDER BY konkurrenceType.kontypeID";
$result = mysql_query($sql) or die(mysql_error());
echo '<option value="Vælg type">Vælg type</option>';
while($rowSelect = mysql_fetch_assoc($result))
{
echo '<option value="' . $rowSelect['kontypeID'] . '">' . $rowSelect['kontypeTitel'] . '</option>';
}?>
</select>
and..
<script>
function run() {
document.getElementById("valgtID").value = document.getElementById("valgtTitel").value;
}
</script>
I get this
INSERT INTO `mah1233411190550`.`konkurrence` ( `konID` , `virkID` , `konTitel` , `konBeskriv` , `konMaal` , `konMaaltype` , `konStart` , `konSlut`, `kontypeID`, `holdID` ) VALUES (NULL , '1', '1', 'cykle', '500', 'km', '2013-01-01', '2018-05-03', '1', '' );
So konTitel is the same as kontypeID, why is that?
You can do something like:
var valgtTitel = document.getElementById("valgtTitel");
document.getElementById("valgtID").value = valgtTitel.options[valgtTitel.selectedIndex].value;
Here's fiddle: http://jsfiddle.net/viralpatel/JYHLM/
Edit:
Perhaps you might want to save the title (apart from ID) in some other textbox and retrieve it from request:
var valgtTitel = document.getElementById("valgtTitel");
document.getElementById("valgtTitle").value = valgtTitel.options[valgtTitel.selectedIndex].innerHTML;
Note how we used innerHTML instead of value to get the title.
So something like this??
<tr>
<td width="180" height="30"><label for="valgtkon" class="labelLeft">Vælg konkurrencetype</label></td>
<td><select id="select" name="select" onchange="run()">
<?php
$virksomhedsID = $_SESSION['virkID'];
$sql = "SELECT * FROM konkurrenceType ORDER BY konkurrenceType.kontypeID";
$result = mysql_query($sql) or die(mysql_error());
echo '<option value="Vælg type">Vælg type</option>';
while($rowSelect = mysql_fetch_assoc($result))
{
$kontypeID = $rowSelect['kontypeID'];
$kontypeTitel = $rowSelect['kontypeTitel'];
echo '<option value="' . $kontypeID . '">' . $kontypeTitel . '</option>';
}?>
</select></td>
<script>
function run() {
var select = document.getElementById("select");
document.getElementById("valgtID").value = valgtTitel.options[select.selectedIndex].innerHTML; //how to make this right?
document.getElementById("valgtTitel").value = valgtTitel.options[select.selectedIndex].innerHTML; //how to make this right?
}
</script>
<td><input type="text" name="valgtID" id="valgtID"/><input type="text" name="valgtTitel" id="valgtTitel"/></td>
</tr>

codeigniter join problem

i have 2 tabels in my database "forum_traad" and "forum_kommentare" but they have the same row "indhold" so when i try to join forum_traad and forum_kommentare and i wanna echo the "indhold" row from "forum_traad" it echo the "indhold" from "forum_kommentare", what can i do?
my view:
<div id="forum">
<?php
if($query)
{
?>
<div class="forum_headline">Forum kategori - Forum tråde - <?php echo $query->overskrift; ?></div><!-- forum_headline -->
<div class="forum_profil_img"></div><!-- forum_profil_img -->
<div class="forum_post_content">
<span style="font-size:15px;"><?php echo anchor('profil/'.$query->brugernavn, $query->brugernavn); ?></span>
<span style="font-size:11px; margin-left:3px; color:#686868;"><i> Siger</i></span><br>
<?php echo $query->indhold;
echo "<br>ID: ".$query->id;
?>
</div><!-- forum_post_content -->
<?php
} else {
echo "Der blev ikke fundet nogen post";
}
?>
</div><!-- forum -->
My model
function posts($id)
{
$this->db->select('*');
$this->db->from('forum_traad');
$this->db->join('forum_kommentare', 'forum_kommentare.fk_forum_traad', 'forum_traad.id');
$this->db->where('forum_traad.id', $id);
$query = $this->db->get();
if($query->num_rows > 0)
{
return $query->row();
} else {
return false;
}
}
You can give them a different name:
$this->db->select('forum_traad.indhold as traad_indhold,
forum_kommentare.indhold as kommentare_indhold');
If you need the functionality of * you can in addition select:
$this->db->select('forum_traad.indhold as traad_indhold,
forum_kommentare.indhold as kommentare_indhold,
forum_traad.*,
forum_kommentare.*');

Resources