public static function checkInventoryOnAddToCart()
 {
     $result = array(true);
     $itemId = Cart66Common::postVal('cart66ItemId');
     $options = '';
     $optionsMsg = '';
     $opt1 = Cart66Common::postVal('options_1');
     $opt2 = Cart66Common::postVal('options_2');
     if (!empty($opt1)) {
         $options = $opt1;
         $optionsMsg = trim(preg_replace('/\\s*([+-])[^$]*\\$.*$/', '', $opt1));
     }
     if (!empty($opt2)) {
         $options .= '~' . $opt2;
         $optionsMsg .= ', ' . trim(preg_replace('/\\s*([+-])[^$]*\\$.*$/', '', $opt2));
     }
     $scrubbedOptions = Cart66Product::scrubVaritationsForIkey($options);
     if (!Cart66Product::confirmInventory($itemId, $scrubbedOptions)) {
         $result[0] = false;
         $p = new Cart66Product($itemId);
         $counts = $p->getInventoryNamesAndCounts();
         $out = '';
         if (count($counts)) {
             $out = '<table class="inventoryCountTableModal">';
             $out .= '<tr><td colspan="2"><strong>' . __('Currently In Stock', 'cart66') . '</strong></td></tr>';
             foreach ($counts as $name => $qty) {
                 $out .= '<tr>';
                 $out .= "<td>{$name}</td><td>{$qty}</td>";
                 $out .= '</tr>';
             }
             $out .= '</table>';
         }
         $soldOutLabel = Cart66Setting::getValue('label_out_of_stock') ? strtolower(Cart66Setting::getValue('label_out_of_stock')) : __('out of stock', 'cart66');
         $result[1] = $p->name . " " . $optionsMsg . " is {$soldOutLabel} {$out}";
     }
     $result = json_encode($result);
     echo $result;
     die;
 }