Skip to content

Commit

Permalink
// Context part 17
Browse files Browse the repository at this point in the history
  • Loading branch information
tDidierjean committed Jul 22, 2011
1 parent 3f9a9e4 commit 112b465
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions admin-dev/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
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',
Expand Down
7 changes: 5 additions & 2 deletions admin-dev/tabs/AdminCarts.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,13 @@ private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency

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 '
<tr>
<td align="center">'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$image->getExistingImgPath().'.jpg',
<td align="center">'.($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') : '--').'</td>
<td><a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&updateproduct&token='.$tokenCatalog.'">
<span class="productName">'.$product['name'].'</span><br />
Expand Down
2 changes: 2 additions & 0 deletions admin-dev/tabs/AdminShipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -189,6 +190,7 @@ public function displayFormHandling()

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);
Expand Down
7 changes: 4 additions & 3 deletions classes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ public function updateQty($quantity, $id_product, $id_product_attribute = NULL,
{
if (!$context)
$context = Context::getContext();

$quantity = (int)$quantity;
$id_product = (int)$id_product;
$id_product_attribute = (int)$id_product_attribute;
Expand Down Expand Up @@ -1590,6 +1589,8 @@ public function deleteCustomizationToProduct($id_product, $index)
* 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)
Expand All @@ -1600,8 +1601,8 @@ public function getProductCustomization($id_product, $type = null, $not_in_cart
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;
Expand Down
13 changes: 8 additions & 5 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3092,13 +3092,16 @@ public function hasAllRequiredCustomizableFields(Context $context = null)
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;
}

Expand Down
1 change: 1 addition & 0 deletions controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public function preProcess()
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))
Expand Down
1 change: 1 addition & 0 deletions install-dev/sql/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion install-dev/sql/upgrade/1.5.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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(); */

0 comments on commit 112b465

Please sign in to comment.