The following code will help to set shipping and billing information. When you execute this script, in return it will give you available payment methods. Continue reading Magento 2 API set shipping and billing information
Tag Archives: Shipping
Magento 2 API Estimate shipping costs
The following code will give you the shipping method available for a given address.
<?php $magentoURL = "http://127.0.0.1/mage2/"; $apiURL = $magentoURL."index.php/rest/V1/integration/customer/token"; $data = array("username" => "Test.User1521623008@phpcodez.com", "password" => "phpcodezpwd"); $data_string = json_encode($data); $ch = curl_init($apiURL); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string))); $token = curl_exec($ch); $customerData = [ 'address' => [ "region" => 'New York', "region_id" => "43", "region_code" => "NY", "country_id" => "US", "street" => array("123 Oak Ave"), "postcode" => "10577", "city" => "Purchase", "firstname" => "Pramod", "lastname" => "Prasad", "customer_id" => "43", "email" => "Test.User1521623008@brandmuscle.com", "telephone" => "(512) 555-1111", "same_as_billing" => "1" ] ]; $requestUrl =$magentoURL.'index.php/rest/V1/carts/mine/estimate-shipping-methods'; $ch = curl_init($requestUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token))); $result = json_decode(curl_exec($ch)); echo "<pre>";print_r($result); ?>
Create Shipping Method Magento 2
Follow the below steps to create a new shipping method in Magento 2 PHPCodez_Easyship
Declare Module – Create module.xml
File : app/code/PHPCode/Easyship/etc/module.xml Continue reading Create Shipping Method Magento 2
Magento 2 query to get all active shipping methods
Following query will help you to get the active shipping methods in magento 2.
select * from core_config_data where path like '%carr%' and path like '%active%' and value=1;
Fetch the shipping address of a logged in user magento
<?php
$customer = Mage::getModel(‘customer/session’)->getCustomer();
foreach($customer->getAddressesCollection() as $address) $shiipingAddress[] = $address->getData();
foreach($shiipingAddress as $value) $region[]=$value[‘region_id’];
print_r($region);
?>
Edit shipping method text on the sidebar on the checkout page Magento
1) Change the directory to magento installation
2) cd app/code/core/Mage/Sales/Model/Quote/Address/Total
3) vi Shipping.php
Edit the code at the line number 168
Edit getShippingDescription() Magento
1) Change the directory to magento installation
2) cd app/code/core/Mage/Sales/Model/Quote/Address/Total
3) vi Shipping.php
Edit the code at the line number 168
Get shipping description magento
<?php
echo Mage::getSingleton(‘checkout/session’)->getQuote()->getShippingAddress()->getShippingMethod()
?>