Esempio n. 1
0
function smartyModifierPP($product, $mode, $wrap = true)
{
    $key = 'pp_' . $mode;
    if (is_array($product)) {
        if (isset($product[$key])) {
            $text = $product[$key];
        }
    }
    if (!isset($text)) {
        $properties = PP::getProductProperties($product);
        if (isset($properties[$key])) {
            $text = $properties[$key];
        }
    }
    return isset($text) && $text != '' ? $wrap === true ? PP::wrap($text, $key) : ($wrap == 'left' ? ' ' . $text : ($wrap == 'right' ? $text . ' ' : $text)) : '';
}
Esempio n. 2
0
 public function productProperties()
 {
     $this->p_properties = PP::getProductProperties($this);
     return $this->p_properties;
 }
Esempio n. 3
0
 public static function smartyConvertPrice($params, &$smarty = null)
 {
     $currency = self::smartyGetCurrency($params);
     $price = array_key_exists('price', $params) ? $params['price'] : null;
     $product = array_key_exists('product', $params) ? $params['product'] : self::$smarty_product;
     if ($product != null) {
         $product_properties = PP::getProductProperties($product);
         $mode = array_key_exists('m', $params) ? $params['m'] : null;
         list($key, $price) = PP::calcProductDisplayPrice($product, $product_properties, $price, $mode);
         $display = is_numeric($price) ? Tools::displayPrice($price, $currency) : ($price === null ? 0 : $price);
         if ($key) {
             $display .= ' <span class="' . $key . '">' . PP::safeOutput($product_properties[$key]) . '</span>';
         }
     } else {
         $display = Tools::displayPrice($price === null ? 0 : $price, $currency);
     }
     return $display;
 }
Esempio n. 4
0
    /**
     * 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);
    }