public function minQty($format = false) { $q = $this->resolveMinQty($this->minimal_quantity, $this->minimal_quantity_fractional); if (PP::qtyPolicyLegacy($this->qtyPolicy())) { $this->minimal_quantity = $q; } else { $this->minimal_quantity_fractional = $q; } return $format ? PP::formatQty($q) : $q; }
protected function _updateCustomizationQuantity($quantity, $id_customization, $id_product, $id_product_attribute, $id_address_delivery, $operator = 'up', $id_cart_product = 0) { // Link customization to product combination when it is first added to cart if (empty($id_customization)) { $customization = $this->getProductCustomization($id_product, null, true); foreach ($customization as $field) { if ($field['quantity'] == 0) { $qty_policy = PP::productQtyPolicy($id_product); $q = PP::normalizeQty($quantity, $qty_policy); Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'customization` SET `quantity` = ' . (PP::qtyPolicyLegacy($qty_policy) ? $q : 1) . ', `quantity_fractional` = ' . (PP::qtyPolicyLegacy($qty_policy) ? 0 : $q) . ', `id_cart_product` = ' . (int) $id_cart_product . ', `id_product_attribute` = ' . (int) $id_product_attribute . ', `id_address_delivery` = ' . (int) $id_address_delivery . ', `in_cart` = 1 WHERE `id_customization` = ' . (int) $field['id_customization']); } } } /* Deletion */ if (!empty($id_customization) && (int) $quantity < 1) { return $this->_deleteCustomization((int) $id_customization, (int) $id_product, (int) $id_product_attribute); } /* Quantity update */ if (!empty($id_customization)) { $result = Db::getInstance()->getRow('SELECT `quantity` FROM `' . _DB_PREFIX_ . 'customization` WHERE `id_customization` = ' . (int) $id_customization); if ($result && Db::getInstance()->NumRows()) { if ($operator == 'down' && (int) $result['quantity'] - (int) $quantity < 1) { return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'customization` WHERE `id_customization` = ' . (int) $id_customization); } return Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'customization` SET `quantity` = `quantity` ' . ($operator == 'up' ? '+ ' : '- ') . (int) $quantity . ', `id_address_delivery` = ' . (int) $id_address_delivery . ' WHERE `id_customization` = ' . (int) $id_customization); } else { Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'customization` SET `id_address_delivery` = ' . (int) $id_address_delivery . ' WHERE `id_customization` = ' . (int) $id_customization); } } // refresh cache of self::_products $this->_products = $this->getProducts(true); $this->update(); return true; }
private function generateDescription($template, $id_lang) { $desc = ''; if ($template['pp_qty_policy'] == 1) { $desc .= $this->l('Product sold in whole units', false, $id_lang); } elseif ($template['pp_qty_policy'] == 2) { if ($template['pp_ext'] > 0) { $desc .= $this->l('Product uses multidimensional feature', false, $id_lang); } else { $desc .= $this->l('Product sold in fractional units', false, $id_lang); } } else { $desc .= $this->l('Product sold in items', false, $id_lang); } if ($template['pp_qty_mode'] && !PP::qtyPolicyLegacy($template['pp_qty_policy'])) { $desc .= ', ' . $this->l('approximate quantity and price (the exact quantity cannot be ordered)', false, $id_lang); } switch ($template['pp_display_mode']) { case 1: $desc .= ', ' . $this->l('reversed price display', false, $id_lang); break; case 2: $desc .= ', ' . $this->l('retail price', false, $id_lang); break; case 3: $desc .= ', ' . $this->l('retail price', false, $id_lang) . ', ' . $this->l('reversed price display', false, $id_lang); break; default: break; } return $desc; }
/** * Add bought product * * @return boolean succeed */ public static function addBoughtProduct($id_wishlist, $id_product, $id_product_attribute, $id_cart, $quantity) { if (!Validate::isUnsignedId($id_wishlist) || !Validate::isUnsignedId($id_product) || !Validate::isUnsignedId($quantity)) { die(Tools::displayError()); } $properties = PP::getProductProperties($id_product); $qty_policy_legacy = PP::qtyPolicyLegacy($properties['pp_qty_policy']); $quantity = PP::resolveInputQty(Tools::getValue('qty'), $properties['pp_qty_policy'], $properties['pp_qty_step'], $quantity); $result = Db::getInstance()->getRow(' SELECT `quantity`, `quantity_fractional`, `id_wishlist_product` FROM `' . _DB_PREFIX_ . 'wishlist_product` wp WHERE `id_wishlist` = ' . (int) $id_wishlist . ' AND `id_product` = ' . (int) $id_product . ' AND `id_product_attribute` = ' . (int) $id_product_attribute); $qty = $qty_policy_legacy ? (int) $result['quantity'] : (double) $result['quantity_fractional']; if (!count($result) || $qty - $quantity < 0 || $quantity > $qty) { return false; } Db::getInstance()->executeS(' SELECT * FROM `' . _DB_PREFIX_ . 'wishlist_product_cart` WHERE `id_wishlist_product`=' . (int) $result['id_wishlist_product'] . ' AND `id_cart`=' . (int) $id_cart); if (Db::getInstance()->NumRows() > 0) { $result2 = Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'wishlist_product_cart` SET `quantity`=`quantity` + ' . ($qty_policy_legacy ? $quantity : 0) . ', `quantity_fractional`=`quantity_fractional` + ' . ($qty_policy_legacy ? 0 : $quantity) . ' WHERE `id_wishlist_product`=' . (int) $result['id_wishlist_product'] . ' AND `id_cart`=' . (int) $id_cart); } else { $result2 = Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'wishlist_product_cart` (`id_wishlist_product`, `id_cart`, `quantity`, `quantity_fractional`, `date_add`) VALUES( ' . (int) $result['id_wishlist_product'] . ', ' . (int) $id_cart . ', ' . ($qty_policy_legacy ? $quantity : 1) . ', ' . ($qty_policy_legacy ? 0 : $quantity) . ', \'' . pSQL(date('Y-m-d H:i:s')) . '\')'); } if ($result2 === false) { return false; } return Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'wishlist_product` SET `quantity`=`quantity` - ' . ($qty_policy_legacy ? $quantity : 0) . ', `quantity_fractional`=`quantity_fractional` - ' . ($qty_policy_legacy ? 0 : $quantity) . ' WHERE `id_wishlist` = ' . (int) $id_wishlist . ' AND `id_product` = ' . (int) $id_product . ' AND `id_product_attribute` = ' . (int) $id_product_attribute); }