I need to append a "specific" product in current order's orderline on the the click on particular button, same functionality needs to be used i.e. when you click on any product and it gets added to orderline. With following line of code, unable to get order id:
this.env.pos.get_order()
I am unable to get in-process order id as it is not yet created in backend until its paid.
To get the order and add a new orderline you can use
var order = this.env.pos.get_order();
order.add_product(product, { quantity: 1, price: total_price });
Related
How can I merge sale order line on a sale order in Odoo programmatically? I have duplicated products in sale order line, I want to remove the duplicated lines but merge the quantity.
Thank you
The best way would be to deal with it at the origin: on sale order line creation : update quantity of an existing line having the same product instead of creating a new sale order line:
class SaleOrderLine(models.Model):
_inherit= 'sale.order.line'
#api.model_create_multi
def create(self, vals_list):
vals_list_newproduct=[]
for values in vals_list:
# if one order line contains a product already existing in this order:
existing_product_soline = self.search(
[('order_id','=',values['order_id'],('product_id','=',values['product_id'])])
if existing_product_soline:
existing_product_soline[0].write({
'product_uom_qty':
float(existing_product_soline[0]['product_uom_qty']) + float(values['product_uom_qty'])
})
else:
#this order line contains a new product for the sale order
vals_list_newproduct.append(values)
#create one new order_line as usual for lines containing new products
super(SaleOrderLine, self).create(vals_list_newproduct)
I want to create a custom module. Firstly I read a XML and get the price by this code:
$price = $product->attributes()->price->__toString();
Then update the product price by using Product object:
$product1 = new Product($id_product);
$product1->price = round($price - (18.69 / 100) * $price, 2);
$product1->save();
This works fine. But how to update combination in product. I have 'id_product_attribute' which I use to update quantity:
StockAvailable::setQuantity($id_product, $attribute['id_product_attribute'], $singleStock, $id_shop = null);
But still I can't find method to update combination price.
Kind regards
if you want to update the price of one of your combinations you'll have to call the object Combination() and use the update() function from there.
I am trying to get the product combinations displayed in Prestashop admin Customer detail view in addition to the products that are displayed for the customer.
This seems to be the relevant call from AdminCustomersController.php in public form renderForm():
$products = $customer->getBoughtProducts();
Then in the Customer class I found the method:
public function getBoughtProducts()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT * FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
WHERE o.valid = 1 AND o.`id_customer` = '.(int)$this->id);
}
How can I modify this method to show the product combination alongside the product name?
I am using Prestashop version 1.6.0.9.
you can get it using 2 ways:
order_detail table already have field 'product_name' that contains value like 'Product Name - Combination', so you can use $products['product_name'] in that case.
or
if for some reason it is not good for you, same table contains also product_attribute_id field, it is combination id, so:
$combination = new Combination($product['product_attribute_id']);
$attributes = $combination->getAttributesName($id_lang);
var_dump($attributes);
will give you array of attributes that current combination contains.
I'm building an iOS app for my own Shopify store. I created a private app and using the API key and password to call APIs with the format:
https://apikey:password#hostname/admin/resource.json
Problem occurs when I try to use the API to make the payment status change for orders. (I can create a new order without problem). I don't find any API for changing the financial status of an order. I cannot change the financial status by modifying an order or I even cannot make any transaction by API no matter the "kind" of transactions is: "authorisation", "capture" or "sale".
So how can I change the financial status of an order using the API?
Here is an example for the request and response of using the API:
Object Called:
/admin/orders/#{order_id}/transactions.json
request:
{
"transaction": {
"amount": 50,
"test":true,
"kind": "sale"
}
}
response:
{"errors":{"kind":["sale is not a valid transaction"]}}
Just a couple of things to try:
I noticed in the Transaction doco there are quotes around the amount, which you don't have in your code (e.g. try "50.00" instead of 50):
POST /admin/orders/#{id}/transactions.json
{
"transaction": {
"amount": "10.00",
"kind": "capture"
}
}
Also, have you seen this discussion on the Shopify forums?
...it seems to work so long as the amount of the transaction doesn't exceed the total outstanding balance of the order. From what I have gathered you can not charge or create a transaction for more than the initial sale amount of the order...
You cannot create a transaction or modify the financial_status of any order created via the Shopify API. Refer http://docs.shopify.com/api/order which explicitly says this.
So essentially, you need to pass the financial_status as 'paid' when creating the order and in case your payment was not successful from the gateway, DELETE the order. http://docs.shopify.com/api/order.html#destroy
I got some problem with changing the status of the order earlier , later i solved, to get rid of error you should take care of the following things.
Price of the order should be equal or less than the exact price of the order
Price < exact order price, order will be labeled as Partial Paid
Price = to the exact order price , order will be labbeled as Paid
Paid Price > exact order price , you will get error
Order with status paid, you will get error to change the status of
payment
POST /admin/orders/#{id}/transactions.json
{
"transaction": {
"amount": "10.00",
"kind": "capture"
}
}
$order_get = $shopify('GET', '/admin/orders/'.$order_id.'.json' );
$total_price = $order_get['total_price'];
if( $order_get['financial_status'] != 'paid' ){
$arguments = array( "order" => array(
'note' => 'Paid'
)
);
$order_put = $shopify('PUT', '/admin/orders/'.$order_id.'.json', $arguments);
$arg = array( "transaction" => array(
"amount" => $total_price,
"kind" => "capture"
)
);
$order_put = $shopify('POST', '/admin/orders/'.$order_id.'/transactions.json', $arg);
}
You're not able to write to the financial_status field to mark an order as paid. The financial_status is a result of the transactions that have taken place on an order. So if an order financial_status is currently authorized, you can mark the order as paid by capturing any funds still owing via our Transaction API - or by marking the order as paid within the admin.
I'm trying to programmatically create an order and invoice in Magento but whenever I add products to the shopping cart, the price of each product is set to 0, thus resulting in a NULL total.
I also tried the moveToCustomerQuote method but that throws a Magento Fault saying that the customer quote (shoppingcart ID) doesn't exist.
Here's my code
$cart = $magi->execute("cart.create");
$add_customer = $magi->execute("cart_customer.set",array($cart,$customer));
$products = array(array(
"product_id" => 167,
"qty" => 50
));
$add_product = $magi->execute("cart_product.add",array($cart,$products));
Is there something I'm doing wrong or is there another step I should take to get the product to list the price properly?