Skip to content

Instantly share code, notes, and snippets.

@hanshasselberg
Created July 3, 2012 10:16
Show Gist options
  • Save hanshasselberg/3038903 to your computer and use it in GitHub Desktop.
Save hanshasselberg/3038903 to your computer and use it in GitHub Desktop.
Add ean13 field to combinations.
commit df5c445ec9fb5e7b0cfb2a4e67ce366226edc79e
Author: Hans Hasselberg <[email protected]>
Date: Tue Jul 3 11:31:01 2012 +0200
Add lieferzeit field to combinations.
diff --git a/themes/prestashop/js/product.js b/themes/prestashop/js/product.js
index 01acb56..a9332c4 100644
--- a/themes/prestashop/js/product.js
+++ b/themes/prestashop/js/product.js
@@ -50,7 +50,7 @@ function oosHookJsCode()
}
//add a combination of attributes in the global JS sytem
-function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity)
+function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, ean13)
{
globalQuantity += quantity;
@@ -64,6 +64,7 @@ function addCombination(idCombination, arrayOfIdAttributes, quantity, price, eco
combination['reference'] = reference;
combination['unit_price'] = unit_price;
combination['minimal_quantity'] = minimal_quantity;
+ combination['ean13'] = ean13;
combinations.push(combination);
}
@@ -104,6 +105,7 @@ function findCombination(firstTime)
//combination of the user has been found in our specifications of combinations (created in back office)
selectedCombination['unavailable'] = false;
selectedCombination['reference'] = combinations[combination]['reference'];
+ selectedCombination['ean13'] = combinations[combination]['ean13'];
$('#idCombination').val(combinations[combination]['idCombination']);
$('#ipa_customization').val(combinations[combination]['idCombination']);
@@ -270,6 +272,17 @@ function updateDisplay()
else
$('#product_reference:visible').hide('slow');
+ if (selectedCombination['ean13'] || productEan13)
+ {
+ if (selectedCombination['ean13'])
+ $('#product_ean13 span').text(selectedCombination['ean13']);
+ else if (productEan13)
+ $('#product_ean13 span').text(productEan13);
+ $('#product_ean13:hidden').show('slow');
+ }
+ else
+ $('#product_ean13:visible').hide('slow');
+
//update display of the the prices in relation to tax, discount, ecotax, and currency criteria
if (!selectedCombination['unavailable'] && productShowPrice == 1)
{
diff --git a/themes/prestashop/product.tpl b/themes/prestashop/product.tpl
index 2d89cf7..b1da9f5 100644
--- a/themes/prestashop/product.tpl
+++ b/themes/prestashop/product.tpl
@@ -61,6 +61,7 @@ var maxQuantityToAllowDisplayOfLastQuantityMessage = {$last_qties};
var noTaxForThisProduct = {if $no_tax == 1}true{else}false{/if};
var displayPrice = {$priceDisplay};
var productReference = '{$product->reference|escape:'htmlall':'UTF-8'}';
+var productEan13 = '{$product->ean13|escape:'htmlall':'UTF-8'}';
var productAvailableForOrder = {if (isset($restricted_country_mode) AND $restricted_country_mode) OR $PS_CATALOG_MODE}'0'{else}'{$product->available_for_order}'{/if};
var productShowPrice = '{if !$PS_CATALOG_MODE}{$product->show_price}{else}0{/if}';
var productUnitPriceRatio = '{$product->unit_price_ratio}';
@@ -109,7 +110,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
{if isset($groups)}
// Combinations
{foreach from=$combinations key=idCombination item=combination}
- addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity});
+ addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity}, '{$combination.ean13}');
{/foreach}
// Colors
{if $colors|@count > 0}
@@ -321,6 +322,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
<p id="product_reference" {if isset($groups) OR !$product->reference}style="display: none;"{/if}><label for="product_reference">{l s='Reference :'} </label><span class="editable">{$product->reference|escape:'htmlall':'UTF-8'}</span></p>
+ <p id="product_ean13" {if isset($groups) OR !$product->ean13}style="display: none;"{/if}><label for="product_ean13">{l s='Lieferzeit :'} </label><span class="editable">{$product->ean13|escape:'htmlall':'UTF-8'}</span></p>
<!-- quantity wanted -->
<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) OR $virtual OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<label>{l s='Quantity :'}</label>
commit df46fc4897df3aad8a795f51cfde2c4f5f0757f8
Author: Hans Hasselberg <[email protected]>
Date: Tue Jul 3 12:18:10 2012 +0200
Disable ean13 validation.
diff --git a/classes/Validate.php b/classes/Validate.php
index c015822..699aa0e 100644
--- a/classes/Validate.php
+++ b/classes/Validate.php
@@ -595,9 +595,9 @@ class ValidateCore
*/
public static function isEan13($ean13)
{
- return !$ean13 OR preg_match('/^[0-9]{0,13}$/', $ean13);
+ return true;
}
diff --git a/classes/Product.php b/classes/Product.php
index 83d1cab..1b5d3d9 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -2899,7 +2899,7 @@ class ProductCore extends ObjectModel
$sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name,
a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pa.`id_product_attribute`,
IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, pa.`weight`,
- product_attribute_shop.`default_on`, pa.`reference`, product_attribute_shop.`unit_price_impact`,
+ product_attribute_shop.`default_on`, pa.`reference`, pa.`ean13`, product_attribute_shop.`unit_price_impact`,
pa.`minimal_quantity`, pa.`available_date`, ag.`group_type`
FROM `'._DB_PREFIX_.'product_attribute` pa
'.Shop::addSqlAssociation('product_attribute', 'pa').'
diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php
index 28508ee..d298304 100644
--- a/controllers/front/ProductController.php
+++ b/controllers/front/ProductController.php
@@ -394,6 +394,7 @@ class ProductControllerCore extends FrontController
$combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight'];
$combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity'];
$combinations[$row['id_product_attribute']]['reference'] = $row['reference'];
+ $combinations[$row['id_product_attribute']]['ean13'] = $row['ean13'];
$combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact'];
$combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity'];
$combinations[$row['id_product_attribute']]['available_date'] = $available_date;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment