Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product Page - Shipping: delivery times #8419

Merged
merged 9 commits into from Oct 30, 2017
7 changes: 7 additions & 0 deletions admin-dev/themes/new-theme/public/theme.css
Expand Up @@ -2245,6 +2245,13 @@ ul.category-tree {
.product-page {
padding-bottom: 80px;
/* Last tab modules selection */ }
.product-page .widget-radio-inline div.radio {
display: inline; }
.product-page .widget-radio-inline label {
display: inline-block; }
.product-page .widget-radio-inline a.btn {
height: 29px;
display: inline; }
.product-page h2 {
padding-top: 20px; }
.product-page .widget-checkbox-inline div.checkbox {
Expand Down
13 changes: 13 additions & 0 deletions admin-dev/themes/new-theme/scss/pages/_product_page.scss
Expand Up @@ -2,6 +2,19 @@

padding-bottom: 80px;

.widget-radio-inline {
div.radio {
display:inline;
}
label {
display:inline-block;
}
a.btn {
height: 29px;
display:inline;
}
}

h2 {
padding-top: 20px;
}
Expand Down
79 changes: 61 additions & 18 deletions classes/Product.php
Expand Up @@ -256,6 +256,36 @@ class ProductCore extends ObjectModel
*/
public $pack_stock_type = 3;

/**
* Type of delivery time
*
* Choose which parameters use for give information delivery.
* 0 - none
* 1 - use default information
* 2 - use product information
*
* @var integer
*/
public $additional_delivery_times = 1;

/**
* Delivery in-stock information
*
* Long description for delivery in-stock product information.
*
* @var string
*/
public $delivery_in_stock;

/**
* Delivery out-stock information
*
* Long description for delivery out-stock product information.
*
* @var string
*/
public $delivery_out_stock;

public static $_taxCalculationMethod = null;
protected static $_prices = array();
protected static $_pricesLevel2 = array();
Expand Down Expand Up @@ -285,24 +315,37 @@ class ProductCore extends ObjectModel
'multilang_shop' => true,
'fields' => array(
/* Classic fields */
'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
'supplier_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
'location' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 64),
'width' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'height' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'depth' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'quantity_discount' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
'isbn' => array('type' => self::TYPE_STRING, 'validate' => 'isIsbn', 'size' => 32),
'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
'cache_is_pack' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'cache_has_attachments' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'is_virtual' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
'supplier_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
'location' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 64),
'width' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'height' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'depth' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
'quantity_discount' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
'isbn' => array('type' => self::TYPE_STRING, 'validate' => 'isIsbn', 'size' => 32),
'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
'cache_is_pack' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'cache_has_attachments' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'is_virtual' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'additional_delivery_times' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'delivery_in_stock' => array(
'type' => self::TYPE_STRING,
'lang' => true,
'validate' => 'isGenericName',
'size' => 255
),
'delivery_out_stock' => array(
'type' => self::TYPE_STRING,
'lang' => true,
'validate' => 'isGenericName',
'size' => 255
),

/* Shop fields */
'id_category_default' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId'),
Expand Down
16 changes: 16 additions & 0 deletions controllers/admin/AdminImportController.php
Expand Up @@ -73,6 +73,8 @@ class AdminImportControllerCore extends AdminController
'online_only' => array('AdminImportController', 'getBoolean'),
'accessories' => array('AdminImportController', 'split'),
'image_alt' => array('AdminImportController', 'split'),
'delivery_in_stock' => array('AdminImportController', 'createMultiLangField'),
'delivery_out_stock' => array('AdminImportController', 'createMultiLangField'),
);

public $separator;
Expand Down Expand Up @@ -246,6 +248,20 @@ public function __construct()
'height' => array('label' => $this->trans('Height', array(), 'Admin.Global')),
'depth' => array('label' => $this->trans('Depth', array(), 'Admin.Global')),
'weight' => array('label' => $this->trans('Weight', array(), 'Admin.Global')),
'delivery_in_stock' => array(
'label' => $this->trans(
'Delivery time of in-stock products:',
array(),
'Admin.Catalog.Feature'
)
),
'delivery_out_stock' => array(
'label' => $this->trans(
'Delivery time of out-of-stock products with allowed orders:',
array(),
'Admin.Advparameters.Feature'
)
),
'quantity' => array('label' => $this->trans('Quantity', array(), 'Admin.Global')),
'minimal_quantity' => array('label' => $this->trans('Minimal quantity', array(), 'Admin.Advparameters.Feature')),
'low_stock_threshold' => array('label' => $this->trans('Low stock level', array(), 'Admin.Catalog.Feature')),
Expand Down
3 changes: 3 additions & 0 deletions install-dev/data/db_structure.sql
Expand Up @@ -1527,6 +1527,7 @@ CREATE TABLE `PREFIX_product` (
`depth` DECIMAL(20, 6) NOT NULL DEFAULT '0',
`weight` DECIMAL(20, 6) NOT NULL DEFAULT '0',
`out_of_stock` int(10) unsigned NOT NULL DEFAULT '2',
`additional_delivery_times` tinyint(1) unsigned NOT NULL DEFAULT '1',
`quantity_discount` tinyint(1) DEFAULT '0',
`customizable` tinyint(2) NOT NULL DEFAULT '0',
`uploadable_files` tinyint(4) NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -1695,6 +1696,8 @@ CREATE TABLE `PREFIX_product_lang` (
`name` varchar(128) NOT NULL,
`available_now` varchar(255) DEFAULT NULL,
`available_later` varchar(255) DEFAULT NULL,
`delivery_in_stock` varchar(255) DEFAULT NULL,
`delivery_out_stock` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_product`, `id_shop` , `id_lang`),
KEY `id_lang` (`id_lang`),
KEY `name` (`name`)
Expand Down
3 changes: 3 additions & 0 deletions install-dev/fixtures/fashion/data/product.xml
Expand Up @@ -24,6 +24,9 @@
<field name="depth"/>
<field name="weight"/>
<field name="out_of_stock"/>
<field name="additional_delivery_times"/>
<field name="delivery_in_stock"/>
<field name="delivery_out_stock"/>
<field name="quantity_discount"/>
<field name="customizable"/>
<field name="uploadable_files"/>
Expand Down
6 changes: 6 additions & 0 deletions install-dev/upgrade/sql/1.7.3.0.sql
Expand Up @@ -9,6 +9,11 @@ UPDATE `PREFIX_tab` SET `position` = 1 WHERE `class_name` = 'AdminCountries' AND
/* PHP:ps_1730_move_some_aeuc_configuration_to_core(); */;

ALTER TABLE `PREFIX_product` ADD `low_stock_threshold` INT(10) NULL DEFAULT NULL AFTER `minimal_quantity`;

ALTER TABLE `PREFIX_product` ADD `additional_delivery_times` tinyint(1) unsigned NOT NULL DEFAULT '1' AFTER `out_of_stock`;
ALTER TABLE `PREFIX_product_lang` ADD `delivery_in_stock` varchar(255) DEFAULT NULL;
ALTER TABLE `PREFIX_product_lang` ADD `delivery_out_stock` varchar(255) DEFAULT NULL;

ALTER TABLE `PREFIX_product_shop` ADD `low_stock_threshold` INT(10) NULL DEFAULT NULL AFTER `minimal_quantity`;

ALTER TABLE `PREFIX_product_attribute` ADD `low_stock_threshold` INT(10) NULL DEFAULT NULL AFTER `minimal_quantity`;
Expand All @@ -19,6 +24,7 @@ ALTER TABLE `PREFIX_product_shop` ADD `low_stock_alert` TINYINT(1) NOT NULL DEFA

ALTER TABLE `PREFIX_product_attribute` ADD `low_stock_alert` TINYINT(1) NOT NULL DEFAULT 0 AFTER `low_stock_threshold`;
ALTER TABLE `PREFIX_product_attribute_shop` ADD `low_stock_alert` TINYINT(1) NOT NULL DEFAULT 0 AFTER `low_stock_threshold`;
ALTER TABLE `PREFIX_product_attribute_shop` ADD `low_stock_threshold` INT(10) NULL DEFAULT NULL AFTER `minimal_quantity`;

CREATE TABLE IF NOT EXISTS `PREFIX_store_lang` (
`id_store` int(11) unsigned NOT NULL,
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Product/ProductPresenter.php
Expand Up @@ -813,6 +813,8 @@ protected function getProductAttributeWhitelist()
"availability_message",
"availability",
"reference_to_display",
"delivery_in_stock",
"delivery_out_stock",
);
}

Expand Down
56 changes: 49 additions & 7 deletions src/PrestaShopBundle/Form/Admin/Product/ProductShipping.php
Expand Up @@ -56,7 +56,7 @@ public function __construct($translator, $legacyContext, $warehouseDataProvider,
$this->warehouses = $warehouseDataProvider->getWarehouses();

$carriers = $carrierDataProvider->getCarriers($this->locales[0]['id_lang'], false, false, false, null, $carrierDataProvider->getAllCarriersConstant());
$this->carriersChoices = [];
$this->carriersChoices = array();
foreach ($carriers as $carrier) {
$this->carriersChoices[$carrier['name'].' ('.$carrier['delay'].')'] = $carrier['id_reference'];
}
Expand All @@ -71,39 +71,39 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('width', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Width', [], 'Admin.Catalog.Feature'),
'label' => $this->translator->trans('Width', array(), 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
)
))
->add('height', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Height', [], 'Admin.Catalog.Feature'),
'label' => $this->translator->trans('Height', array(), 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
)
))
->add('depth', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Depth', [], 'Admin.Catalog.Feature'),
'label' => $this->translator->trans('Depth', array(), 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
)
))
->add('weight', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Weight', [], 'Admin.Catalog.Feature'),
'label' => $this->translator->trans('Weight', array(), 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
)
))
->add('additional_shipping_cost', 'Symfony\Component\Form\Extension\Core\Type\MoneyType', array(
'required' => false,
'label' => $this->translator->trans('Shipping fees', [], 'Admin.Catalog.Feature'),
'label' => $this->translator->trans('Shipping fees', array(), 'Admin.Catalog.Feature'),
'currency' => $this->currency->iso_code,
'constraints' => array(
new Assert\NotBlank(),
Expand All @@ -116,9 +116,51 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'expanded' => true,
'multiple' => true,
'required' => false,
'label' => $this->translator->trans('Available carriers', [], 'Admin.Catalog.Feature')
'label' => $this->translator->trans('Available carriers', array(), 'Admin.Catalog.Feature')
))
->add('additional_delivery_times', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
'choices' => array(
'0' => $this->translator->trans('None', array(), 'Admin.Catalog.Feature'),
'1' => $this->translator->trans('Default delivery time', array(), 'Admin.Catalog.Feature'),
'2' => $this->translator->trans('Specific delivery time to this product', array(), 'Admin.Catalog.Feature'),
),
'expanded' => true,
'multiple' => false,
'required' => false,
'empty_value' => false,
'preferred_choices' => array('default'),
'label' => $this->translator->trans('Delivery Time', array(), 'Admin.Catalog.Feature')
))
->add('delivery_out_stock', 'PrestaShopBundle\Form\Admin\Type\TranslateType', array(
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
'options' => array(
'attr' => array(
'placeholder' => $this->translator->trans('Delivered within 5-7 days', array(), 'Admin.Catalog.Feature'),
)
),
'locales' => $this->locales,
'hideTabs' => true,
'required' => false,
'label' => $this->translator->trans(
'Delivery time of out-of-stock products with allowed orders:',
array(),
'Admin.Catalog.Feature'
),
))
->add('delivery_in_stock', 'PrestaShopBundle\Form\Admin\Type\TranslateType', array(
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
'options' => array(
'attr' => array(
'placeholder' => $this->translator->trans('Delivered within 3-4 days', array(), 'Admin.Catalog.Feature'),
)
),
'locales' => $this->locales,
'hideTabs' => true,
'required' => false,
'label' => $this->translator->trans('Delivery time of in-stock products:', array(), 'Admin.Catalog.Feature'),
));


foreach ($this->warehouses as $warehouse) {
$builder->add('warehouse_combination_'.$warehouse['id_warehouse'], 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array(
'entry_type' =>'PrestaShopBundle\Form\Admin\Product\ProductWarehouseCombination',
Expand Down
5 changes: 5 additions & 0 deletions src/PrestaShopBundle/Model/Product/AdminModelAdapter.php
Expand Up @@ -126,6 +126,8 @@ public function __construct(
'available_now',
'available_later',
'tags',
'delivery_in_stock',
'delivery_out_stock',
);

//define unused key for manual binding
Expand Down Expand Up @@ -476,6 +478,9 @@ function ($p) {
'weight' => $this->product->weight,
'additional_shipping_cost' => $this->product->additional_shipping_cost,
'selectedCarriers' => $this->getFormProductCarriers(),
'additional_delivery_times' => $this->product->additional_delivery_times,
'delivery_in_stock' => $this->product->delivery_in_stock,
'delivery_out_stock' => $this->product->delivery_out_stock,
],
'step5' => [
'link_rewrite' => $this->product->link_rewrite,
Expand Down
Expand Up @@ -70,7 +70,48 @@
</div>
</div>

<div class="col-md-12 my-4">
<div class="col-md-12">
<div class="form-group">
<h2>
{{ form.additional_delivery_times.vars.label }}
<span class="help-box" data-toggle="popover"
data-content="{{ "Display delivery time for a product is advised for merchants selling in Europe to comply with the local laws."|trans({}, 'Admin.Catalog.Help') }}" ></span>
</h2>
<div class="row">
<div class="col-md-12" {{ block('widget_container_attributes') }}>
{% for child in form.additional_delivery_times %}
{% if child.vars.value == 1 %}
<div class="widget-radio-inline">
{{ form_widget(child) }}
<a href="{{ getAdminLink("AdminPPreferences") }}" class="btn sensitive px-0" target=_blank><i class="material-icons">open_in_new</i> {{ "edit"|trans({}, 'Admin.Catalog.Help') }}</a>
</div>
{% else %}
{{ form_widget(child) }}
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>

<div class="col-xl-6 col-lg-6">
<div class="form-group">
<label class="form-control-label">{{ form.delivery_in_stock.vars.label }}</label>
{{ form_errors(form.delivery_in_stock) }}
{{ form_widget(form.delivery_in_stock) }}
<p class="subtitle italic">{{ 'Leave empty to disable.'|trans({}, 'Admin.Catalog.Feature') }}</p>
</div>
</div>
<div class="col-xl-6 col-lg-6">
<div class="form-group">
<label class="form-control-label">{{ form.delivery_out_stock.vars.label }}</label>
{{ form_errors(form.delivery_out_stock) }}
{{ form_widget(form.delivery_out_stock) }}
<p class="subtitle italic">{{ 'Leave empty to disable.'|trans({}, 'Admin.Catalog.Feature') }}</p>
</div>
</div>

<div class="col-md-12">
<div class="form-group">
<h2>
{{ form.additional_shipping_cost.vars.label }}
Expand Down