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 increaseInventory($id, $variation = '', $qty = 1) { Cart66Common::log("Increasing Inventory: line " . __LINE__); // Build varation ikey string component if (!empty($variation)) { $variation = self::scrubVaritationsForIkey(str_replace(', ', '~', $variation)); } $p = new Cart66Product($id); $is_gravity_form = false; $valid_options = array(); if ($p->isGravityProduct()) { $valid_options = Cart66GravityReader::getFormValuesArray($p->gravity_form_id); $is_gravity_form = true; } else { if (strlen($p->options_1) > 1) { $valid_options[] = explode(',', str_replace(' ', '', $p->options_1)); } if (strlen($p->options_2) > 1) { $valid_options[] = explode(',', str_replace(' ', '', $p->options_2)); } } $newVariation = ''; $options = explode(',', $variation); foreach ($options as $option) { if ($p->validate_option($valid_options, $option, $is_gravity_form)) { $newVariation .= $option; } } $ikey = $p->getInventoryKey($newVariation); $count = $p->getInventoryCount($ikey); $newCount = $count + $qty; $p->setInventoryLevel($ikey, $newCount); }