How to show correct item count in Magento 2 Checkout Order summary?

By default, app/design/Magento/Checkout/view/frontend/web/template/summary/cart-items.html file is being used
Or vendor/magento/module-checkout/view/frontend/web/template/summary/cart-items.html

To overload this file, create file cart-items.html in your theme folder. Make sure you place the file in Magento_Checkout/web/template/summary/

Edit the line

<span data-bind="text: getCartLineItemsCount()"></span>

And replace it with

<span data-bind="text: getItemsQty()"></span>

Reference Files:

vendor/magento/module-checkout/view/frontend/web/js/view/summary/cart-items.js

https://github.com/magento/magento2/blob/2.2/app/code/Magento/Checkout/view/frontend/web/template/summary/cart-items.html

https://github.com/magento/magento2/blob/2.2/app/code/Magento/Checkout/view/frontend/web/js/view/summary/cart-items.js

How to dump all options for any attribute in Magento 2 programmatically?

The following code does not adhere to Magento’s developer recommendations. Using object manager in such a way externally is a TERRIBLE idea.

Comment out line number 2 and then run the script. Edit line 11 and put the attribute code you want to dump

<?php
header("Location: /");exit;
use \Magento\Framework\App\Bootstrap;
error_reporting(E_ALL);
ini_set("display_errors", 1);
include('./app/bootstrap.php');
$bootstrap     = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$eavConfig = $objectManager->get('\Magento\Eav\Model\Config');
$attribute = $eavConfig->getAttribute('catalog_product', 'manufacturer');
$options   = $attribute->getSource()->getAllOptions();
$options   = array_slice($options, 1);
usort($options, function($a, $b)
{
    return strcasecmp($a['label'], $b['label']);
});
if (count($options))
    $v = "<table>";
foreach ($options as $option) {
    $v .= "<tr><td>" . $option['value'] . '</td><td>' . $option['label'] . '</td></tr>';
}
if (count($options))
    $v .= "</table>";
echo $v;
?>
   <style>
    table tr:nth-child(odd){background:#444;color:#fff}
   </style>

How to remove files with “No Content Changes Found” in Git Desktop

There are 3 possible ways git can find a file changed (even if you didn’t change it)

  1. Line Endings have changed
  2. File permissions have changed
  3. Bonus: if modification time has changed

for first case try these settings in bash shell. One of these will fix it for you

$ git config core.eol
$ git config core.autocrlf
$ git config core.safecrlf

For second case, here is the flag

git config core.filemode false

Bonus One: If Modification time was changed

If your working tree has files with updated “last modification time” and you see a huge list of files with “no content changes found”, try this:

git add .
 // ^ dont use . [DOT] if you want to fix for particular sub-folder

You can do git add for all affected files, after that it stops displaying them as modified in git status (and doesn’t actually stage them for commit if there are no changes).

References: https://stackoverflow.com/a/37221298/2229148

Mouse and Keyboard sharing across Computers

We use multiple computers in workspace or in home. Often need to share same mouse and keyboard for all because you probably have a wireless/wired keyboard mouse set. here arises the issue that how to share same set of input controllers for both machines.

Below are a few free and paid options for you to choose from. They all work as expected when computers are connected via LAN or WiFi

  1. Mouse without Borders
  2. Barrier
  3. ShareMouse
  4. Synergy

Microsoft Garage Mouse without Borders

This is all time classic program to share clipboard, mouse movements and what not. For windows to windows mouse sharing this is the best.

It is FREE too

Barrier

This is best alternative in FREE category. It supports MAC OS and Windows both. so this is the one you should go with if you dont have just windows machines.

Sharemouse

This is a good one for cross OSs. It supports both windows and apple mac. Free version is okayish. Can get a bit buggy if you are using a HDMI switch for same monitor mirroring. But still gets the job done.

If you got some bucks to spare, use the paid version which has more features

Synergy

Synergy is the best paid software for this purpose. HANDS DOWN

Supports MAC, Windows and Linux just like the others but provides you support (because you have paid)

How to fix Undefined class constant ‘ARRAY_AS_PROPS’ Fatal Error?

I received this error “Fatal Error: Uncaught error in Undefined class constant ‘ARRAY_AS_PROPS'”
This issue is not related to PHP if you have 7.0 and above, it is zend framework’s module zend-http wrapper which is affected if Apache module is not present

File responsible: zendframework\zend-http\src\Header\Cookie.php:75

public function __construct(array $array = [])
{
        parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
}

Solution

Do check enabled modules for Apache, I found out that mod_expires was not enabled. So I edited httpd.conf and enabled mod_expires

I also enabled Zend Opcache in php.ini to make it run smooth on multiple pageloads.

Quick tips on American SALES TAX for developers who are setting up an ecommerce store for USA based organization

So, all of the info you read below is the summary of 6 hours I spent yesterday in gathering information about taxes in USA. – to be particular – Sales Tax. Not Income tax

To start with, USA has 50 states, meaning constituent political entity. All states have their own rules for sales tax and there is no nation-wide sales tax as such. So if you are an store owner in any particular, you will have to charge your customers taxes, which you are supposed to pay to the state.

Now when I say “charge your customers taxes”, I mean- obviously that is why you are here. There are two types of taxes based on the final location of the product after the purchase.

So there are origin based taxes and destination based taxes. Some states require you to charge customer depending upon your (seller’s) location. Summary- If you are located in an origin-based state and make sales to customers within that state, you would charge sales tax based on your location, including any local and state taxes.  Example – Illinois

Destination Based tax – If you are in state A and you make a sale to a customer living in state B, you have an obligation to collect and pay sales tax of state B, ONLY if you have a Nexus in state B

Now you must be wondering Nexus, what is a nexus in tax terms? So a nexus is kind of a link of your business to/in a certain state. Lets say your business is Registered and has a brick mortar office in state X, and you sell a lot to customers in state Y. Depending upon the volume and nature of transactions, State government requires you to register a Nexus in state Y so that you can collect sales tax for State Y- as simple as that. However, terms and legislation criteria on whether you should register a Nexus vary a lot from state to state. But it usually comes in scope when you are selling 250,000+ USD in a state which is not your home state.

Home state means where you run business.

Summary: You only charge sales tax if your customer’s shipping address is in your home state i.e., where your store is. Customers out of your state dont need to pay any taxes which purchasing from you.

Now coming to tax rates:

Tax rates are honestly very confusing when talking about USA. They have unreal system of managing tax rates and enduring tax-evasion problem.

Usually states have same taxes or even some countries have a fixed tax depending upon the product hierarchy, but that is not the case with USA.

There are chances that two addresses in same pincode will have different tax rates, YES! I am NOT kidding!

As per jurisdictions, the tax rates are combined. There is a State Tax Rate, County Tax Rate and City Tax Rate and maybe others too.

Combining all these give you an estimated tax rate which can be categorized per Pincode or ZIPcode but wont be 100% accurate. An Example is here – ZIP Codes: The wrong tool for the job However the article seems like an exaggeration because they want to sell their product/service of course.

Bottom Line- It can get really messy when dealing with Sales Tax in USA. Since I am not the tax guy and have no relation with accountancy whatsoever, there are chances that many of the things I stated above might be wrong. However, I believe that what I read online and the information that I gathered was from trust-able sources. The e-commerce store setup that I did was based on Magento 2, so I managed to create tax rates for each state. Later on, I found out I only needed to create tax rates for only one state i.e., our home state.

Here is a full list of all states combined: USA-allpincodes-mar2019.csv

And you can use following tax rates area wise- in Magento2 format

AlabamaIndianaNebraskaRhode Island
AlaskaIowaNevadaSouth Carolina
ArizonaKansasNew HampshireSouth Dakota
ArkansasKentuckyNew JerseyTennessee
CaliforniaLouisianaNew MexicoTexas
ColoradoMaineNew YorkUtah
ConnecticutMarylandNorth CarolinaVermont
DelawareMassachusettsNorth DakotaVirginia
FloridaMichiganOhioWashington
GeorgiaMinnesotaOklahomaWashington, DC
HawaiiMississippiOregonWest Virginia
IdahoMissouriPennsylvaniaWisconsin
IllinoisMontanaPuerto RicoWyoming

Reference for CSVs: https://www.avalara.com/taxrates/en/download-tax-tables.html

Reference for other details:
1. https://www.avalara.com/us/en/learn/whitepapers/origin-vs-destination-sales-tax.html
2. https://blog.taxjar.com/states-where-amazon-com-collects-sales-tax/
3. https://en.wikipedia.org/wiki/Sales_taxes_in_the_United_States
4. https://quickbooks.intuit.com/r/taxes/what-is-nexus-and-how-does-it-affect-your-small-business/

How to transpose an array in PHP with irregular subarray size?

    function transposeCsvData($data)
    {
	    $ct=0;
	    foreach($data as $key => $val)
        {
	        //echo count($val);
		    if($ct< count($val))
                $ct=count($val);
		    }
		//echo $ct;
	    $blank=array_fill(0,$ct,array_fill(0,count($data),null));
	    //print_r($blank);
	
	    $retData = array();
        foreach ($data as $row => $columns)
        {
            foreach ($columns as $row2 => $column2) 
            {
                $retData[$row2][$row] = $column2;
                }
            }
	    $final=array();
	    foreach($retData as $k=>$aval)
	    { 
            $final[]=array_replace($blank[$k], $aval);
           }
        return $final;
        }

Test Code

$a[]=array("name","john","sam","patrick");
$a[]=array("color","orange","green");
$a[]=array("bikes","suzuki","audi","mercedes","bmw","volks","rover");
$a[]=array("techgiants","samsung","amazon");

print_r(transposeCsvData($a));

Output

Array
(
    [0] => Array
        (
            [0] => name
            [1] => color
            [2] => bikes
            [3] => techgiants
        )

    [1] => Array
        (
            [0] => john
            [1] => orange
            [2] => suzuki
            [3] => samsung
        )

    [2] => Array
        (
            [0] => sam
            [1] => green
            [2] => audi
            [3] => amazon
        )

    [3] => Array
        (
            [0] => patrick
            [1] => 
            [2] => mercedes
            [3] => 
        )

    [4] => Array
        (
            [0] => 
            [1] => 
            [2] => bmw
            [3] => 
        )

    [5] => Array
        (
            [0] => 
            [1] => 
            [2] => volks
            [3] => 
        )

    [6] => Array
        (
            [0] => 
            [1] => 
            [2] => rover
            [3] => 
        )

)

SQL Notes

CREATE TABLE `clients` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `name` varchar(11) NOT NULL,
  `associate` varchar(100) NOT NULL,
  `revenue` int(12) NOT NULL,
  `profit` int(12) NOT NULL,
   PRIMARY KEY (`id`),
   FOREIGN key (`associate`) references `emp`(`emp_code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

alter table `emp` add COLUMN `phone` int(12) not null after `name`
alter table `emp` add COLUMN `phone` int(12) null after `name`
alter table `emp` modify `phone` int(12) null
alter table `emp` drop column `phone`


ALTER TABLE `emp`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `emp_code` (`emp_code`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `emp`
--
ALTER TABLE `emp`
  MODIFY `id` int(4) NOT NULL AUTO_INCREMENT;
COMMIT;