public static function showCartAnchor($attrs, $content) { $product = new Cart66Product(); $product->loadFromShortcode($attrs); $options = isset($attrs['options']) ? $attrs['options'] : ''; $urlOptions = isset($attrs['options']) ? '&options=' . urlencode($options) : ''; $content = do_shortcode($content); $iCount = true; $iKey = $product->getInventoryKey($options); if ($product->isInventoryTracked($iKey)) { $iCount = $product->getInventoryCount($iKey); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] iCount: {$iCount} === iKey: {$iKey}"); } else { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Not tracking inventory for: {$iKey}"); } if ($iCount) { $id = $product->id; $class = isset($attrs['class']) ? $attrs['class'] : ''; $cartPage = get_page_by_path('store/cart'); $cartLink = get_permalink($cartPage->ID); $joinChar = strpos($cartLink, '?') === FALSE ? '?' : '&'; $data = array('url' => $cartLink . $joinChar . "task=add-to-cart-anchor&cart66ItemId={$id}{$urlOptions}", 'text' => $content, 'class' => $class); $view = Cart66Common::getView('views/cart-button-anchor.php', $data, true, true); } else { $view = $content; } return $view; }
public static function confirmInventory($id, $variation = '', $desiredQty = 1) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Confirming Inventory:\n{$id} | {$variation} | {$desiredQty}"); $ok = true; $setting = new Cart66Setting(); $trackInventory = Cart66Setting::getValue('track_inventory'); if ($trackInventory == 1) { $p = new Cart66Product($id); $variation = self::scrubVaritationsForIkey($variation); $ikey = $p->getInventoryKey($variation); if ($p->isInventoryTracked($ikey)) { $qty = self::checkInventoryLevelForProduct($id, $variation); if ($qty < $desiredQty) { $ok = false; } } else { Cart66Common::log("Inventory not tracked: {$ikey}"); } } return $ok; }