wdrożenia PrestaShop Powiększenie zdjęć moduł

Maksymalna ilosc przy zmodyfikowanym kodzie

  • 0 Odpowiedzi
  • 1531 Wyświetleń

0 użytkowników i 2 Gości przegląda ten wątek.

*

Offline Keenic

  • Nowy
  • *
  • 2
  • 0
Maksymalna ilosc przy zmodyfikowanym kodzie
« dnia: Maj 08, 2012, 07:05:37 pm »
Witam, modyfikuje prestashop tak aby obslugiwala podana przez uzytkownika wysokosc oraz szerokosc produktu.
Zmodyfikowalem dodawanie produktow tak, ze dodawane sa do bazy te wartosci i teraz chcialbym zrobic, aby ten sam produkt przy wpisaniu innej wysokosci badz szerokosci dodawany byl jako kolejny produkt, a nie zwiekszona ilosc. Niestety pokazuje sie komunikat, ze mam juz maksymalna ilosc produktu.
Oto moja funkcja updateQty:
public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', $width, $height)
{
$product = new Product((int)$id_product, false, (int)Configuration::get('PS_LANG_DEFAULT'));

/* If we have a product combination, the minimal quantity is set with the one of this combination */
if (!empty($id_product_attribute))
$minimalQuantity = (int)Attribute::getAttributeMinimalQty((int)$id_product_attribute);
else
$minimalQuantity = (int)$product->minimal_quantity;

if (!Validate::isLoadedObject($product))
die(Tools::displayError());
if (isset(self::$_nbProducts[$this->id]))
unset(self::$_nbProducts[$this->id]);
if (isset(self::$_totalWeight[$this->id]))
unset(self::$_totalWeight[$this->id]);
if ((int)$quantity <= 0)
return $this->deleteProduct((int)$id_product, (int)$id_product_attribute, (int)$id_customization);
else if (!$product->available_for_order OR Configuration::get('PS_CATALOG_MODE'))
return false;
else
{
/* Check if the product is already in the cart */
$result = $this->containsProduct((int)$id_product, (int)$id_product_attribute, (int)$id_customization);
                       
/* Update quantity if product already exist */
if ($result AND ($width == $result['width'] OR $height == $result['height']))
{
if ($operator == 'up')
{
$result2 = Db::getInstance()->getRow('
SELECT '.(!empty($id_product_attribute) ? 'pa' : 'p').'.`quantity`, p.`out_of_stock`
FROM `'._DB_PREFIX_.'product` p
'.(!empty($id_product_attribute) ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON p.`id_product` = pa.`id_product`' : '').'
WHERE p.`id_product` = '.(int)($id_product).
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : ''));
$productQty = (int)$result2['quantity'];
$newQty = (int)$result['quantity'] + (int)$quantity;
$qty = '+ '.(int)$quantity;

if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock']))
if ($newQty > $productQty)
return false;
}
elseif ($operator == 'down')
{
$qty = '- '.(int)$quantity;
$newQty = (int)$result['quantity'] - (int)$quantity;
if ($newQty < $minimalQuantity AND $minimalQuantity > 1)
return -1;
}
else
return false;

/* Delete product from cart */
if ($newQty <= 0)
return $this->deleteProduct((int)$id_product, (int)$id_product_attribute, (int)$id_customization);
else if ($newQty < $minimalQuantity)
return -1;
else
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cart_product`
SET `quantity` = `quantity` '.$qty.', `date_add` = NOW()
WHERE `id_product` = '.(int)$id_product.
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '').'
AND `id_cart` = '.(int)$this->id.'
LIMIT 1');
}

/* Add product to the cart */
else
{
$result2 = Db::getInstance()->getRow('
SELECT '.(!empty($id_product_attribute) ? 'pa' : 'p').'.`quantity`, p.`out_of_stock`
FROM `'._DB_PREFIX_.'product` p
'.(!empty($id_product_attribute) ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON p.`id_product` = pa.`id_product`' : '').'
WHERE p.`id_product` = '.(int)$id_product.
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : ''));

if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock']))
if ((int)$quantity > $result2['quantity'])
return false;

if ((int)$quantity < $minimalQuantity)
return -1;

if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.'cart_product', array('id_product' => (int)$id_product, 'id_product_attribute' => (int)$id_product_attribute, 'id_cart' => (int)$this->id,
'quantity' => (int)$quantity, 'width' => $width, 'height' => $height, 'date_add' => date('Y-m-d H:i:s')), 'INSERT'))
return false;
}
}
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
$this->update(true);

if ($product->customizable)
return $this->_updateCustomizationQuantity((int)$quantity, (int)$id_customization, (int)$id_product, (int)$id_product_attribute, $operator);
else
return true;
}
W funkcji containsProduct dodalem wyswietlanie wysokosci oraz szerokosci.
I tutaj moje pytanie, jak powinienem zmodyfikowac funkcje updateQty, a nie wyswietlal sie ten komunikat.