diff --git a/admin-dev/pdf.php b/admin-dev/pdf.php
index 5e0ed25d4..039d58fed 100644
--- a/admin-dev/pdf.php
+++ b/admin-dev/pdf.php
@@ -30,9 +30,15 @@ define('PS_ADMIN_DIR', getcwd());
include(PS_ADMIN_DIR.'/../config/config.inc.php');
/* Header can't be included, so cookie must be created here */
+$context = Context::getContext();
+
$cookie = new Cookie('psAdmin');
if (!$cookie->id_employee)
Tools::redirectAdmin('login.php');
+
+$context->employee = new Employee($cookie->id_employee);
+$context->language = new Language($context->employee->id_lang);
+$context->country = $defaultCountry;
$functionArray = array(
'pdf' => 'generateInvoicePDF',
diff --git a/admin-dev/tabs/AdminCarts.php b/admin-dev/tabs/AdminCarts.php
index e6316a6f3..c9e8efe18 100644
--- a/admin-dev/tabs/AdminCarts.php
+++ b/admin-dev/tabs/AdminCarts.php
@@ -258,10 +258,13 @@ class AdminCarts extends AdminTab
if (is_array($customizedDatas) AND isset($customizedDatas[(int)($product['id_product'])][(int)($product['id_product_attribute'])]))
{
- $image = new Image($image['id_image']);
+ if (isset($image['id_image']))
+ $image = new Image($image['id_image']);
+ else
+ $image = new Image();
echo '
- | '.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$image->getExistingImgPath().'.jpg',
+ | '.($image->id ? cacheImage(_PS_IMG_DIR_.'p/'.$image->getExistingImgPath().'.jpg',
'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').' |
'.$product['name'].'
diff --git a/admin-dev/tabs/AdminShipping.php b/admin-dev/tabs/AdminShipping.php
index d6aa54931..17d9624bf 100644
--- a/admin-dev/tabs/AdminShipping.php
+++ b/admin-dev/tabs/AdminShipping.php
@@ -32,6 +32,7 @@ class AdminShipping extends AdminTab
public function __construct()
{
+ $context = Context::getContext();
$this->table = 'delivery';
$this->_fieldsHandling = array(
'PS_SHIPPING_HANDLING' => array('title' => $this->l('Handling charges'), 'suffix' => $context->currency, 'validation' => 'isPrice', 'cast' => 'floatval'),
@@ -189,6 +190,7 @@ class AdminShipping extends AdminTab
public function displayFormFees()
{
+ $context = Context::getContext();
$carrierArray = array();
$id_carrier = Tools::getValue('id_carrier');
$carriers = Carrier::getCarriers(Configuration::get('PS_LANG_DEFAULT'), true , false,false, NULL, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
diff --git a/classes/Cart.php b/classes/Cart.php
index fdd8461fd..876cc9443 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -545,7 +545,6 @@ class CartCore extends ObjectModel
{
if (!$context)
$context = Context::getContext();
-
$quantity = (int)$quantity;
$id_product = (int)$id_product;
$id_product_attribute = (int)$id_product_attribute;
@@ -1590,6 +1589,8 @@ class CartCore extends ObjectModel
* Return custom pictures in this cart for a specified product
*
* @param int $id_product
+ * @param int $type only return customization of this type
+ * @param bool $not_in_cart only return customizations that are not in cart already
* @return array result rows
*/
public function getProductCustomization($id_product, $type = null, $not_in_cart = false)
@@ -1600,8 +1601,8 @@ class CartCore extends ObjectModel
ON cu.`id_customization` = cd.`id_customization`
WHERE cu.id_cart = '.(int)$this->id.'
AND cu.id_product = '.(int)$id_product.
- ($type == 0 ? ' AND type = 0' : '').
- ($type == 1 ? ' AND type = 1' : '').
+ ($type === _CUSTOMIZE_FILE_ ? ' AND type = '.(int)_CUSTOMIZE_FILE_ : '').
+ ($type === _CUSTOMIZE_TEXTFIELD_ ? ' AND type = '.(int)_CUSTOMIZE_TEXTFIELD_ : '').
($not_in_cart ? ' AND in_cart = 0' : '')
);
return $result;
diff --git a/classes/Product.php b/classes/Product.php
index efd8b421c..b243bf89d 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -3092,13 +3092,16 @@ class ProductCore extends ObjectModel
if (!$context)
$context = Context::getContext();
- $fields = array_merge($context->cookie->getFamily('pictures_'.(int)($this->id)), $context->cookie->getFamily('textFields_'.(int)($this->id)));
+ $fields = $context->cart->getProductCustomization($this->id, null, true);
if (($requiredFields = $this->getRequiredCustomizableFields()) === false)
return false;
- $prefix = array(_CUSTOMIZE_FILE_ => 'pictures_'.(int)($this->id).'_', _CUSTOMIZE_TEXTFIELD_ => 'textFields_'.(int)($this->id).'_');
- foreach ($requiredFields AS $field)
- if (!isset($fields[$prefix[$field['type']].$field['id_customization_field']]) OR empty($fields[$prefix[$field['type']].$field['id_customization_field']]))
- return false;
+
+ $fields_present = array();
+ foreach ($fields as $field)
+ $fields_present[] = array('id_customization_field' => $field['index'], 'type' => $field['type']);
+ foreach ($requiredFields AS $required_field)
+ if (!in_array($required_field, $fields_present))
+ return false;
return true;
}
diff --git a/controllers/CartController.php b/controllers/CartController.php
index 121bf7249..1470eb764 100644
--- a/controllers/CartController.php
+++ b/controllers/CartController.php
@@ -172,6 +172,7 @@ class CartControllerCore extends FrontController
if ($context->cart->id)
$context->cookie->id_cart = (int)$context->cart->id;
}
+
if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId)
$this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.');
if (!sizeof($this->errors))
diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql
index a0a1b46f4..a5b05cc68 100644
--- a/install-dev/sql/db.sql
+++ b/install-dev/sql/db.sql
@@ -489,6 +489,7 @@ CREATE TABLE `PREFIX_customization` (
`quantity` int(10) NOT NULL,
`quantity_refunded` INT NOT NULL DEFAULT '0',
`quantity_returned` INT NOT NULL DEFAULT '0',
+ `in_cart` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id_customization`,`id_cart`,`id_product`),
KEY `id_product_attribute` (`id_product_attribute`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
diff --git a/install-dev/sql/upgrade/1.5.0.0.sql b/install-dev/sql/upgrade/1.5.0.0.sql
index dc21a89fa..8cb33b3f2 100755
--- a/install-dev/sql/upgrade/1.5.0.0.sql
+++ b/install-dev/sql/upgrade/1.5.0.0.sql
@@ -300,8 +300,10 @@ CREATE TABLE `PREFIX_referrer_shop` (
INSERT INTO `PREFIX_referrer_shop` (`id_referrer`, `id_shop`) SELECT `id_referrer`, 1 FROM `PREFIX_referrer`;
ALTER TABLE `PREFIX_referrer` DROP `cache_visitors`, DROP `cache_visits`, DROP `cache_pages`, DROP `cache_registrations`, DROP `cache_orders`, DROP `cache_sales`, DROP `cache_reg_rate`, DROP `cache_order_rate`;
-ALTER TABLE PREFIX_employee ADD `show_screencast` tinyint(1) unsigned NOT NULL default '1';
+ALTER TABLE `PREFIX_employee` ADD `show_screencast` TINYINT(1) UNSIGNED NOT NULL default '1';
ALTER TABLE `PREFIX_cart_product` ADD `id_shop` INT NOT NULL DEFAULT '1' AFTER `id_product`;
+ALTER TABLE `PREFIX_customization` ADD `in_cart` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0';
+
/* PHP:create_multistore(); */
|