Magento calculate shipping rates base on total weight, province and country
I am new to Magento and I need to calculate shipping rates base on total weight in cart, province and the country during checkout, I have created an api to output rates in json format, but I have no idea how to call to the api in Magento. Usually I used to request the api through http request, but in magento I don't know how to integrate my api in it.
is there any plugin so that I can simply use?
See also questions close to this topic

Edit Magento Configuration settings by file (cant save)
I'm having an issue with a magento site where nothing will save, but my error logs are disabled in
System > Configuration > Developer > Log Settings
I can't update them via the admin panel as the issue i'm having will not let me enable them and save the changes, but I can't fix it because I have no error log. Its a vicious cycle!
How can I edit the config settings not using the admin panel? Either my xml file edit or changing the database variable?

magento 1.9 shipping method custom module with restful API system
I could not see the result of the fire, but from the postman came out the result. If there are errors in my code?
<?php class SmashingMagazine_MyCarrier_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface { protected $_code = 'smashingmagazine_mycarrier'; public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!Mage::getStoreConfig('carriers/'.$this>_code.'/active')) { return false; } $result = Mage::getModel('shipping/rate_result'); $show = true; $result>append($this>getRegPrice()); return $result; } public function getAllowedMethods() { return array('smashingmagazine_mycarrier'=>$this>getConfigData('name')); } protected function getRegPrice() { $cost=''; $curl=curl_init(); curl_setopt_array($curl, array( CURLOPT_PORT => "10101", CURLOPT_URL => "http://apiv2.jne.co.id:10101/tracing/api/pricedev/", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "username=PETROHUBGLOBALSOLUSINDO&api_key=186d9eb507fc8d64d10b194b6521fbfc&from=CGK10000&thru=MGL10503&weight=1", CURLOPT_HTTPHEADER => array( "accept: application/json", "cachecontrol: nocache", "contenttype: application/xwwwformurlencoded", "postmantoken: 1f0e6a561aa62da1ca46f30ba9d652c1" ), )); $respons=curl_exec($curl); $data=file_get_contents($respons); $prcArray=json_decode($data, true); $price=print_r($prcArray['price'][0]>price); $prcObject=json_decode($data, true); $name=print_r($prcObject['price']['0']>destination_name); $method = Mage::getModel('shipping/rate_result_method'); $method>setCarrier($this>_code); $method>setCarrierTitle($this>getConfigData('title')); $method>setMethod($prc['price'][0]['origin_name']); $method>setMethodTitle($name); $method>setPrice($price); $method>setCost($price); return $method; } } ?>
Following is the result from the postman.
{ "price": [ { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "JTR", "service_code": "JTR", "goods_type": "Paket", "currency": "IDR", "price": "80000", "etd_from": null, "etd_thru": null, "times": null }, { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "JTR250", "service_code": "JTR250", "goods_type": "Paket", "currency": "IDR", "price": "2200000", "etd_from": null, "etd_thru": null, "times": null }, { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "JTR<150", "service_code": "JTR<150", "goods_type": "Paket", "currency": "IDR", "price": "1500000", "etd_from": null, "etd_thru": null, "times": null }, { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "JTR>250", "service_code": "JTR>250", "goods_type": "Paket", "currency": "IDR", "price": "2800000", "etd_from": null, "etd_thru": null, "times": null }, { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "OKE", "service_code": "OKE15", "goods_type": "Document/Paket", "currency": "IDR", "price": "24000", "etd_from": "3", "etd_thru": "6", "times": "D" }, { "origin_name": "JAKARTA", "destination_name": "NEGARA,KAB.JEMBRANA", "service_display": "REG", "service_code": "REG15", "goods_type": "Document/Paket", "currency": "IDR", "price": "28000", "etd_from": "2", "etd_thru": "3", "times": "D" } ] }
Please help.
 How to add a Search by Index (Alphabetical) in Header Magento 1.9.1

Email recipients based on Shipping method Id for Woocommerce new order notification
In Woocommerce, I would like to have a new order email sent to specific persons based on the selected shipping method ID.
Right now, I am only able to have every email address added to the new order email, but ultimately want to have the email be sent to one specific email based on the shipping method Id selected by the customer.
Here is my code coming from this answer that works for postal code:
add_filter( 'new_order' , 'so_26429482_add_recipient', 20, 2 ); function so_26429482_add_recipient( $email, $order ) { $additional_email = "somebody@somewhere.net"; if( $order>shipping_postcode == "90210" ){ $email = explode( ',', $email ); array_push( $email, $additional_email ); } return $email; }
Instead I should need to target the shipping method Id.
My two shipping methods Ids are
flat_rate:8
andflat_rate:9
.Does anyone know how to do this?

Where is woocommerce_package_rates applied?
I have a shipping plugin that is employing the woocommerce_package_rates filter. Where is this filter applied?
The shipping logic is running twice on each request and therefore doubling my API calls. I need to track this down.

Formula to add shipping cost for defined iteration of cart quantity
Let's assume that we have these variables.
// base shipping cost of product $product_shipping_cost = 10; // You can send 4 same products in the same pack with $product_shipping_cost $product_shipping_interval_quantity = 4; // Your current quantity in cart $cart_quantity = 9; // defined total shipping cost, should be in this case 30; // because 9 in $cart quantity $total_shipping_cost = 0;
How should this work in real life? So basically we have this:
 When $cart_quantity == 1 then $total_shipping_cost is 10$
 When $cart_quantity <= 4 then $total_shipping_cost is still 10$
 When $cart_quantity == 5 then $total_shipping_cost should be 20$
 When $cart_quantity <= 8 then $total_shipping_cost is still 20$
 When $cart_quantity == 9 then $total_shipping_cost should be 30$
 and so on and so forth ...
How to achieve such a formula? I tried to
$total_shipping_cost = $product_shipping_cost * floor($cart_quantity/$product_shipping_interval_quantity)
But it doesn't work, it changing only when 4/8/12 etc not on 5/9/13 and it is not starting with 10 when ie: 2 pcs in cart.

Creating an A/B Test Sample Size Calculator from Evan Miller's Simple Sequential A/B Testing Blog
To learn more about A/B Testing sample sizes selection I am attempting to use Evan Miller's popular blogpost to recreate a sample size calculator (https://www.evanmiller.org/sequentialabtesting.html). However, there seems to be an error that prevents me from recreating the sample sizes given in article. What would you suggest I reexamine to find a solution to my problem?
This error must be in my calculation or my reading of the problem. Solving the constraint equations suggests a small sample size of ~6. The article suggests that the test statistic cutoff, which indicates if the treatment has a higher conversion rate than the control, is a function of the sample size. Then it list two inequalities to solve for one variable, N the sample size. How do I reproduce the sample size calculations?
Most of these problems would go away if the test statistic cutoff, d_star, wasn't a function of N.
d_star = z*Sqrt(N), N is the sample size and z is the normal zvalue
However, On the tables appearing the last half of the article d_star = z*Sqrt(N) relates N and d_star very precisely, which suggests d_star varies with N.
Constraints given alpha and beta: Sum R(p=1/(1+delta)) > 1  beta Sum R(p=1/2) < alpha
I'll append my Python 2.7 code and a plot for each constrain equation.
#### Begin Python Code to Calculate Sample Size #### import random import scipy.stats import math import sys print sys.version # Functions and helper functions to # calculate the sample size. def calcStatPowerSum(N, script_delta): z = scipy.stats.norm.isf(alpha/2.0) #1.96 for alpha = 0.05 d_star = z*(N**0.5) d_star = int(math.ceil(d_star)) statPowerSum = 0 for i in range(1, N+1): statPowerSum += (float(d_star)/i)*scipy.stats.binom.pmf((i+d_star)//2, i, 1.0float(1)/(2+script_delta)) # p and the (1p) terms are reversed relative to the binomial distribution return statPowerSum def calcCritValueSum(N, script_delta): z = scipy.stats.norm.isf(alpha/2.0) #1.96 for alpha = 0.05 d_star = z*(N**0.5) d_star = int(math.ceil(d_star)) critValueSum = 0 for i in range(d_star, N+1, 2): critValueSum += (float(d_star)/i)*scipy.stats.binom.pmf((i+d_star)//2, i, 0.5) return critValueSum def determineSampleSize(alpha, beta, script_delta): z = scipy.stats.norm.isf(alpha/2.0) #1.96 for alpha = 0.05 d=1 N=int(math.ceil(z*z))1 statPowerSum = 0 critValueSum = 1 while (statPowerSum <= 1  beta or critValueSum >= alpha) and N<3000: d+=1 N=int(math.floor(d*d/z/z)) statPowerSum = calcStatPowerSum(N, script_delta) critValueSum = calcCritValueSum(N, script_delta) return N alpha = 0.05 beta = 0.8 lift = script_delta = 0.10 sampleSize = determineSampleSize(alpha, beta, script_delta) print("beta: ", beta, ", alpha: ", alpha, ", sampleSize: ", sampleSize) ## The article suggests that N=2922 satisfies the constraint equations. ## But the calculation suggests otherwise. print("calcCritValueSum: ", calcCritValueSum(2922, script_delta)) print("statPowerSum: ", calcStatPowerSum(2922, script_delta)) #### End Python Code ####
The following mathematica code reproduces the constraint plots as a function of d_star. Copy and pasting the code into https://sandbox.open.wolframcloud.com/ will generate these plots. Generating more than one plot at a time will exceed the free usage limit.
(* alpha constraint Plot *) z=1.96 (*alpha=0.05*) Table[Sum[(d/n)*PDF[BinomialDistribution[Floor[d^2/z^2], 1/2], (d+n)/2], {n, d, Floor[d^2/z^2], 2}],{d,1,130}] ListLinePlot[%, PlotRange>All, AxesLabel>{d_star,prob},PlotLabel>alpha Constraint Plot] (* 1beta constraint Plot *) delta=0.10 z=1.96 (*alpha=0.05*) Table[Sum[(d/n)*PDF[BinomialDistribution[Floor[d^2/z^2], (1+delta)/(2+delta)], (d+n)/2], {n, d, Floor[d^2/z^2], 2}],{d,1,130}] ListLinePlot[%, PlotRange>All, AxesLabel>{d_star,prob},PlotLabel>1 beta Constraint Plot]

Growth Rate of all columns
I have a dataframe which consist of 23 variables. I want to calculate the growth rate by lag 1 of the first 22 variables. I tried to make a list
mylist
of all 22 columns and then use lapply function but it is not working. The dataset is calleddata_nse
temp4 < lapply(mylist,function(x){ data_nse$x < (xlag(x,1))/lag(x,1) x})
I get the following error
> Error in attr(x, "tsp") < c(1, NROW(x), 1) : invalid time series > parameters specified
What is the correct and efficient way to do this? I am new to R.
Thanks in advance!