Limit Maximum Weight in Cart in Opencart 2.0.3.1 - opencart2.x

I am using opencart 2.0.3.1
I want to restrict the Maximum Total order to 35 KG (35000 GM)
How to restrict and alert on View Cart Page and Disable the checkout if all product collective weight is greater than 35 KG

I assume your default Product Weight is KG.
In catalog/controller/checkout/checkout.php add this function inside class ControllerCheckoutCheckout
public function checkCartWeight($allwed_weight,$error_message){
$cart = $this->cart->getProducts();
$cart_weight = array_sum(array_column($cart, 'weight'));
if($allwed_weight<$cart_weight){
$this->session->data['error'] = $error_message;
$this->response->redirect($this->url->link('checkout/cart'));
}
}
Now you can call the checkCartWeight($allwed_weight,$error_message) in your index()
$allwed_weight = 35;
$error_message = "Cart Weight limit is $allwed_weight KG";
$this->checkCartWeight($allwed_weight,$error_message);

Related

How to get price of actual product in Drupal Commerce?

Hi guys im new in drupal, i start to learn drupal 3 month before.
Im trying to get the price number of the product i get the total cart like this
$user_id = \Drupal::currentUser()->id();
$orders = \Drupal::entityTypeManager()
->getStorage('commerce_order')
->loadByProperties(['uid' => $user_id]);
$orderPrice = [];
foreach($orders as $key => $value) {
$orderPrice[] = $value->getTotalPrice()->getNumber();
}
$total = $orderPrice[count($orderPrice)-1];
$total= number_format($total, 2);
Im trying to do something similar with te product.
For example if iam in the product 1 get the price of product 1, if i am in the product 2 get the price of product 2.
Thanks for your time :)

How to get Remaining Amount of Customer Deposits in Saved Search (includes SuiteScript code)

I need to get the Remaining Balance of all Customer Deposits linked to a specific Sales Order
Remaining Balance = the available/unapplied amount
Below, I will show you how I solved this in a saved search.
As a bonus, I'll also include the SuiteScript 1.0 code to do the same.
To show the Remaining Amount of all Customer Deposits linked to a specific Sales Order record:
Create a Transaction Saved Search as follows:
Criteria (Use Expressions)
( Type IS Deposit Application AND
Created From Fields > Sales Order IS Sales Order #xyz ) OR
( Type IS Customer Deposit AND
Created From IS Sales Order #xyz )
Results
Formula (Numeric) (Summary type SUM): CASE WHEN {type} = 'Customer Deposit' THEN {debitamount} ELSE -{creditamount} END
BONUS, SuiteScript 1.0 code to get Remaining Amount of all Customer Deposits linked to a specific Sales Order record:
function customerDepositsRemainingBalance(salesorder_internalid) {
var filters = [[["type","anyof","DepAppl"],"AND",["createdfrom.salesorder","anyof",salesorder_internalid]],"OR",[["type","anyof","CustDep"],"AND",["createdfrom","anyof",salesorder_internalid]]];
var columns = [new nlobjSearchColumn('formulanumeric',null,'SUM')];
columns[0].setFormula("CASE WHEN {type} = 'Customer Deposit' THEN {debitamount} ELSE -{creditamount} END");
var search = nlapiSearchRecord('transaction',null,filters,columns);
if(search == null) return 0;
return Number(search[0].getValue(columns[0]));
}
// Example Usage
balance = customerDepositsRemainingBalance(3247434); // returns 50
balance = customerDepositsRemainingBalance(3256644); // returns 0

Acumatica Web API Apply Discounts

I am trying to get a way to obtain the discount code from the web service API, i.e would there be a function call that could tell me which discount code to apply?
I am otherwise attempting to retrieve the discount codes but they can be by Item or By Item Price Class and Customer etc etc which is making the code longer than expected.
Hopeing there is a "GetBestDiscount" facility in the API that could help me?
Thanks,
G
At this moment Acumatica Discount Engine is deactivated for any Web Service call. Due to this fact, entering an order line without any discount will not populate the discount code.
However, at Acumatica University there is the GetSalesPrice.zip customization package made specifically to retrieving the price of an Item for a Customer (attached to the I200 Screen-Based Web Services 5.3 and the I210 Contract-Based Web Services 5.3 sources).
Sample call for Screen-Based API:
Content getSalesPriceSchema = context.GetSchema();
var commands = new Command[]
{
new Value
{
Value = customer,
LinkedCommand =getSalesPriceSchema.RequiredInputParameters.Customer
},
new Value
{
Value = inventoryID,
LinkedCommand =getSalesPriceSchema.RequiredInputParameters.InventoryID
},
getSalesPriceSchema.OutputPrice.Price
};
Content price = context.Submit(commands)[0];
Sample call for Contract-Based API:
GetSalesPriceInquiry priceToBeGet = new GetSalesPriceInquiry
{
Customer = new StringValue { Value = customer },
InventoryID = new StringValue { Value = inventoryID }
};
GetSalesPriceInquiry stockItemPrice = (GetSalesPriceInquiry)soapClient.Put(priceToBeGet);
I tried creating a temporary Sales order line via API Order Entry Screen without saving it as Gabriel suggestion.
I can retrieve the set price no problems but the Discount Percentage and Discount Code is not returned.
The discount percentage returned is zero and the discount Code is blank.
This is because the Acumatica Discount Engine is deactivated for any Web Service call I guess.
Any reason why the Acumatica Discount Engine is deactivated for any Web Service calls?
There is no such API, however you could use the sales order entry screen API to create a temporary sales order, add one line to it and retrieve the set price or discount without saving the order. This will be the most accurate information, since discounts and price can also depend on the date, quantity and also on other products being ordered at the same time.

Displaying the total sum of values from strings

My project is a simple shopping game where the user types in the quantity amount, and the value of the individual prices appears and then a total sum can appear below.
I have managed to create the part of displaying the individual product price but i am confused on how to add the total sum and display correctly at the instance that i defined.
Some info
Actionscript will check for keypress event
sample of code snippet:
if(e.keyCode == 49){ //1
trace("Key Code Pressed: " + e.keyCode);
amount1.text = "1.00"
}
...
var total:Number = amount1+ amount2+amount3+amount4+amount5;
output1.text = String(total);
From the code above, when the user types 1, the price will change to "1.00" on the price instance field (dynamic text type).
Picture below:
A sample of my game running:
Total price should be $13.00 dollars..
Is there any way to make this happen? I believe is it something to do with parseint.
You should be able to string together multiple parseint statements like this:
var total:number = parseint(amount1.text) + parseint(amount2.text) + parseint(amount3.text) + parseint(amount4.text) + parseint(amount5.text);
output1.text = total;
If you go this route, you will need to handle stituations that involve NaN
Here is the documentation on parseint if you haven't already, you should look at it. http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000590.html

Magento upfront payment

For a future project we have been assigned to create a simple concept (inside Magento) that would has to do the following:
A customer has the ability to choose between different shipping methods, one of them being "Ship2Shop", which sends the product to a physical store of choice and the customer has to go an pick it up.
When a customer selects this "ship2shop" shipping method, a certain percentage (eg: 25%) of the total amount has to be paid online (via a pre-defined payment method) and the remaining 75% has to be paid in the physical store when the customer goes and pick up the products he ordered.
How would you go about this?
Idea that we were having is modify the checkout/order session and modify the "grand total" amount (saving the original in a session ofcourse). When the customer is then sent to the external payment processor the "modified grand total" is sent along. Once the customer returns on the magento platform we would modify the order by restoring the original grand total the way it was and updating the total paid and total due amount.
Anyone got any other ideas about this?
EDIT:
After feedback from Anton S below I managed to add an "advance payment total". However Im still having a problem
In the config.xml I have added the following in the tag:
acsystems_advancepayment/total_custom
grand_total
I want my advance payment to show AFTER the grand total, for some reason, magento won't do that...
EDIT2: Collect method
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
$quote = $address->getQuote();
$advancePaymentAmount = 0;
$baseAdvancePaymentAmount = 0;
$items = $address->getAllItems();
if (!count($items)) {
$address->setAdvancePaymentAmount($advancePaymentAmount);
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
return $this;
}
$address->setBaseAdvancePayment($address->getGrandTotal()*(0.25));
$address->setAdvancePayment($address->getGrandTotal()*(0.25));
$address->setAdvancePaymentAmount($address->getGrandTotal()*(0.25));
$address->setBaseAdvancePaymentAmount($address->getGrandTotal()*(0.25));
$address->setGrandTotal($address->getGrandTotal() - $address->getAdvancePaymentAmount());
$address->setBaseGrandTotal($address->getBaseGrandTotal()-$address->getBaseAdvancePaymentAmount());
return $this;
}
refer to this thread where adding total objects is explained Magento: adding duties/taxes to a quote during review
Basically you should add your own total object based on your shipping method selection, then it will also be shown in totals as separate row and you can show this in every e-mail or place where totals are exposed
public function collect(Mage_Sales_Model_Quote_Address $address)
{
//this is for the loop that you are in when totals are collected
parent::collect($address);
$quote = $address->getQuote();
//variables for your own object context
$advancePaymentAmount = 0;
$baseAdvancePaymentAmount = 0;
$items = $address->getAllItems();
if (!count($items)) {
$address->setAdvancePaymentAmount($advancePaymentAmount);
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
return $this;
}
//calculated based on other total object and don't edit other totals inside your own as your calculations would be always false and so would be next total object in the cycle and so on
$baseAdvancePaymentAmount = $address->getBaseGrandTotal()*(0.25);
$advancePaymentAmount = $address->getQuote()->getStore()->convertPrice($baseAdvancePaymentAmount, false);
//this is just for your own object context
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
$address->setAdvancePaymentAmount($advancePaymentAmount);
/*
* this is for the loop that you are in when totals are collected and
* those are set to 0 for each totals collecting cycle
*/
$this->_setBaseAmount($baseAdvancePaymentAmount);
$this->_setAmount($advancePaymentAmount);
return $this;
}
Another option is to change the "grand_total" in your payment module, that way the sessions aren't altered..

Resources