Inheritance: extends ActiveRecord\Model
 function getContent()
 {
     $is_one_dot_five = version_compare(_PS_VERSION_, '1.5', '>');
     // Smarty
     $template_vars = array('id_tab' => Tools::getValue('id_tab'), 'controller' => Tools::getValue('controller'), 'tab' => Tools::getValue('tab'), 'configure' => Tools::getValue('configure'), 'tab_module' => Tools::getValue('tab_module'), 'module_name' => Tools::getValue('module_name'), 'token' => Tools::getValue('token'), 'ebay_token' => Configuration::get('EBAY_SECURITY_TOKEN'), '_module_dir_' => _MODULE_DIR_, 'ebay_categories' => EbayCategoryConfiguration::getEbayCategories($this->ebay_profile->id), 'id_lang' => $this->context->cookie->id_lang, 'id_ebay_profile' => $this->ebay_profile->id, '_path' => $this->path, 'possible_attributes' => AttributeGroup::getAttributesGroups($this->context->cookie->id_lang), 'possible_features' => Feature::getFeatures($this->context->cookie->id_lang, true), 'date' => pSQL(date('Ymdhis')), 'conditions' => $this->_translatePSConditions(EbayCategoryConditionConfiguration::getPSConditions()), 'form_items_specifics' => EbaySynchronizer::getNbSynchronizableEbayCategoryCondition(), 'form_items_specifics_mixed' => EbaySynchronizer::getNbSynchronizableEbayCategoryConditionMixed(), 'isOneDotFive' => $is_one_dot_five);
     return $this->display('formItemsSpecifics.tpl', $template_vars);
 }
 public function __construct($moduleInstance)
 {
     parent::__construct($moduleInstance);
     $productIdOptions = array(array('value' => 0, 'name' => 'Reference Code'), array('value' => 1, 'name' => 'EAN-13 or JAN barcode'), array('value' => 2, 'name' => 'UPC barcode'));
     $this->addSelectField('Product ID', 'map_id', $productIdOptions, true, $this->l('Select the product reference group you are using in your store'));
     $productManufacturerOptions = array(array('value' => 0, 'name' => 'Product Manufacturer'), array('value' => 1, 'name' => 'Product Supplier'));
     $this->addSelectField('Product Manufacturer', 'map_manufacturer', $productManufacturerOptions, true, $this->l('Select the field you are using to specify the manufacturer'));
     $productLinkOptions = array(array('value' => 0, 'name' => 'Use Product Link'));
     $this->addSelectField('Product Link', 'map_link', $productLinkOptions, true, $this->l('URL that leads to product. For upcoming features'));
     $productImageLinkOptions = array(array('value' => 0, 'name' => 'Cover Image'), array('value' => 1, 'name' => 'Random Image'));
     $this->addSelectField('Product Image', 'map_image', $productImageLinkOptions, true, $this->l('Choose if you want to use cover image or some random image from product\'s gallery'));
     $productCategoriesOptions = array(array('value' => 0, 'name' => 'Categories'), array('value' => 1, 'name' => 'Tags'));
     $this->addSelectField('Product Categories', 'map_category', $productCategoriesOptions, true, $this->l('Choose product tags if and only if no categories are set and instead product tags are in use'));
     $productPriceOptions = array(array('value' => 0, 'name' => 'Retail price with tax'), array('value' => 1, 'name' => 'Pre-tax retail price'), array('value' => 2, 'name' => 'Pre-tax wholesale price'));
     $this->addSelectField('Product Prices', 'map_price_with_vat', $productPriceOptions, true, $this->l('s option specify the product price that will be used in XML. This should be left to "Retail price with tax"'));
     $productMPNOptions = array(array('value' => 0, 'name' => 'Reference Code'), array('value' => 1, 'name' => 'EAN-13 or JAN barcode'), array('value' => 2, 'name' => 'UPC barcode'), array('value' => 3, 'name' => 'Supplier Reference'));
     $this->addSelectField('Product Manufacturer Reference Code', 'map_mpn', $productMPNOptions, true, $this->l('This option should reflect product\' manufacturer SKU'));
     $productISBNOptions = array(array('value' => 0, 'name' => 'Reference Code'), array('value' => 1, 'name' => 'EAN-13 or JAN barcode'), array('value' => 2, 'name' => 'UPC barcode'), array('value' => 3, 'name' => 'Supplier Reference'));
     $this->addSelectField('Product ISBN', 'map_isbn', $productISBNOptions, true, $this->l('This field will be used if you sell books in your store, to specify the ISBN of the book'));
     // Multiselect from attribute groups
     $default_lang = (int) \Configuration::get('PS_LANG_DEFAULT');
     $productSizesOptions = array();
     $productColorOptions = array();
     $attributes = \AttributeGroup::getAttributesGroups($default_lang);
     foreach ($attributes as $attribute) {
         if ($attribute['is_color_group']) {
             $productColorOptions[] = array('value' => $attribute['id_attribute_group'], 'name' => $attribute['name']);
         } else {
             $productSizesOptions[] = array('value' => $attribute['id_attribute_group'], 'name' => $attribute['name']);
         }
     }
     $this->addMultiSelectField('Size Attributes', 'map_size', $productSizesOptions, true, $this->l('Choose the attributes that you use to specify product sizes. This field is used only if Fashion Store option is enabled'))->addMultiSelectField('Color Attributes', 'map_color', $productColorOptions, true, $this->l('Choose the attributes that you use to specify product colors. This field is used only if Fashion Store option is enabled'));
 }
 public function actionDelete($ids)
 {
     $ids = explode(',', $ids);
     if (count($ids) > 0) {
         foreach ($ids as $id) {
             $attributeGroup = AttributeGroup::model()->findByPk($id);
             $attributeGroup->delete();
         }
     }
     $this->redirect(array('index'));
 }
Exemplo n.º 4
0
 public function save()
 {
     $attributeGroup = AttributeGroup::model()->findByPk($this->id);
     if (is_null($attributeGroup)) {
         // is insert
         $attributeGroup = new AttributeGroup();
         $attributeGroup->sort_order = $this->sortOrder;
         $attributeGroup->save();
         $attributeDescription = new AttributeGroupDescription();
         $attributeDescription->attribute_group_id = $attributeGroup->attribute_group_id;
         $attributeDescription->language_id = 1;
         // TODO: read locale
         $attributeDescription->name = $this->name;
         $attributeDescription->save();
     } else {
         $attributeGroup->sort_order = $this->sortOrder;
         $attributeGroup->save();
         $attributeGroup->description->name = $this->name;
         $attributeGroup->description->save();
     }
 }
 public function actionSort()
 {
     if (isset($_POST['items']) && is_array($_POST['items'])) {
         $i = 0;
         foreach ($_POST['items'] as $item) {
             $project = AttributeGroup::model()->findByPk($item);
             $project->sort_order = $i;
             $project->save();
             $i++;
         }
     }
 }
Exemplo n.º 6
0
 public function __construct()
 {
     $this->name = 'topshop';
     $this->tab = 'smart_shopping';
     $this->version = '1.7.7';
     $this->author = 'Roman Prokofyev';
     $this->need_instance = 1;
     $this->display = 'view';
     $this->bootstrap = true;
     //$this->ps_versions_compliancy = array('min' => '1.5.0.0', 'max' => '1.6');
     $this->module_key = '2149d8638f786d69c1a762f1fbfb8124';
     $this->custom_attributes = array('YAMARKET_COMPANY_NAME', 'YAMARKET_DELIVERY_PRICE', 'YAMARKET_SALES_NOTES', 'YAMARKET_COUNTRY_OF_ORIGIN', 'YAMARKET_EXPORT_TYPE', 'YAMARKET_MODEL_NAME', 'YAMARKET_DESC_TYPE', 'YAMARKET_DELIVERY_DELIVERY', 'YAMARKET_DELIVERY_PICKUP', 'YAMARKET_DELIVERY_STORE');
     $this->country_of_origin_attr = Configuration::get('YAMARKET_COUNTRY_OF_ORIGIN');
     $this->model_name_attr = Configuration::get('YAMARKET_MODEL_NAME');
     parent::__construct();
     $this->displayName = $this->l('Yandex Market');
     if ($this->id && !Configuration::get('YAMARKET_COMPANY_NAME')) {
         $this->warning = $this->l('You have not yet set your Company Name');
     }
     $this->description = $this->l('Provides price list export to Yandex Market');
     $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
     // Variables fro price list
     $this->id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
     $this->proto_prefix = _PS_BASE_URL_;
     // Get groups
     $attribute_groups = AttributeGroup::getAttributesGroups($this->id_lang);
     $this->attibute_groups = array();
     foreach ($attribute_groups as $group) {
         $this->attibute_groups[$group['id_attribute_group']] = $group['public_name'];
     }
     // Get categories
     $this->excluded_cats = explode(',', Configuration::get('TOPSHOP_EXCLUDED_CATS'));
     if (!$this->excluded_cats) {
         $this->excluded_cats = array();
     }
     $all_cats = Category::getSimpleCategories($this->id_lang);
     $this->selected_cats = array();
     $this->all_cats = array();
     foreach ($all_cats as $cat) {
         $this->all_cats[] = $cat['id_category'];
         if (!in_array($cat['id_category'], $this->excluded_cats)) {
             $this->selected_cats[] = $cat['id_category'];
         }
     }
     //determine image type
     $this->image_type = 'large_default';
     if (Tools::substr(_PS_VERSION_, 0, 5) == '1.5.0') {
         $this->image_type = 'large';
     }
 }
Exemplo n.º 7
0
 public function get_index($cat = '', $alias = '')
 {
     //Filtering the Attribute groups for product specific
     if (empty($alias)) {
     }
     $prod = Product::with(array('getCategory', 'getCategory.getDescriptions'))->where('alias', '=', $cat)->first();
     $cat = $prod->getCategory[0]->getDescriptions->alias;
     $alias = $prod->alias;
     $category_id = CategoryDescription::with('getCategory')->where('alias', '=', $cat)->only('id');
     $result = Category::with(array("getDescriptions", "getTopCat", "getTopCat.getDescriptions", "getProducts" => function ($query) use($alias) {
         $query->where('alias', '=', $alias);
     }, "getProducts.getBrand", "getProducts.getImages", "getProducts.getDetail", "getProducts.getTax", "getProducts.getDiscount", "getProducts.getAttributes", "getProducts.getShipment", "getAttributeListing", "getAttributeListing.getTopGroup"))->where('id', '=', $category_id)->first();
     Title::put($result->getProducts[0]->getDetail->name);
     /*Get attributes*/
     $topGroups = array();
     foreach ($result->getAttributeListing as $item) {
         array_push($topGroups, $item->getTopGroup->id);
     }
     $topGroups = array_unique($topGroups);
     $groups = array();
     foreach ($result->getAttributeListing as $item) {
         array_push($groups, $item->id);
     }
     $groups = array_unique($groups);
     $belongedGroups = array();
     foreach ($result->getProducts[0]->getAttributes as $item) {
         array_push($belongedGroups, $item->id);
     }
     $attrs = AttributeGroup::with(array('getParentGroup' => function ($query) use($groups) {
         $query->order_by('sort_order', 'desc');
         $query->where_in('id', $groups);
     }, 'getParentGroup.getAttributes' => function ($query) use($belongedGroups) {
         $query->where_in('id', $belongedGroups);
     }))->where_in('id', $topGroups)->get();
     return View::make('products.index')->with('product', $result)->with('attrs', $attrs);
 }
    public function renderForm()
    {
        $back = Tools::safeOutput(Tools::getValue('back', ''));
        if (empty($back)) {
            $back = self::$currentIndex . '&token=' . $this->token;
        }
        $this->toolbar_btn['save-and-stay'] = array('href' => '#', 'desc' => $this->l('Save and Stay'));
        $current_object = $this->loadObject(true);
        // All the filter are prefilled with the correct information
        $customer_filter = '';
        if (Validate::isUnsignedId($current_object->id_customer) && ($customer = new Customer($current_object->id_customer)) && Validate::isLoadedObject($customer)) {
            $customer_filter = $customer->firstname . ' ' . $customer->lastname . ' (' . $customer->email . ')';
        }
        $gift_product_filter = '';
        if (Validate::isUnsignedId($current_object->gift_product) && ($product = new Product($current_object->gift_product, false, $this->context->language->id)) && Validate::isLoadedObject($product)) {
            $gift_product_filter = !empty($product->reference) ? $product->reference : $product->name;
        }
        $reduction_product_filter = '';
        if (Validate::isUnsignedId($current_object->reduction_product) && ($product = new Product($current_object->reduction_product, false, $this->context->language->id)) && Validate::isLoadedObject($product)) {
            $reduction_product_filter = !empty($product->reference) ? $product->reference : $product->name;
        }
        $product_rule_groups = $this->getProductRuleGroupsDisplay($current_object);
        $attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id);
        $currencies = Currency::getCurrencies();
        $languages = Language::getLanguages();
        $countries = $current_object->getAssociatedRestrictions('country', true, true);
        $groups = $current_object->getAssociatedRestrictions('group', false, true);
        $shops = $current_object->getAssociatedRestrictions('shop', false, false);
        $cart_rules = $current_object->getAssociatedRestrictions('cart_rule', false, true);
        $carriers = $current_object->getAssociatedRestrictions('carrier', true, false);
        foreach ($carriers as &$carriers2) {
            foreach ($carriers2 as &$carrier) {
                foreach ($carrier as $field => &$value) {
                    if ($field == 'name' && $value == '0') {
                        $value = Configuration::get('PS_SHOP_NAME');
                    }
                }
            }
        }
        $gift_product_select = '';
        $gift_product_attribute_select = '';
        if ((int) $current_object->gift_product) {
            $search_products = $this->searchProducts($gift_product_filter);
            foreach ($search_products['products'] as $product) {
                $gift_product_select .= '
				<option value="' . $product['id_product'] . '" ' . ($product['id_product'] == $current_object->gift_product ? 'selected="selected"' : '') . '>
					' . $product['name'] . (count($product['combinations']) == 0 ? ' - ' . $product['formatted_price'] : '') . '
				</option>';
                if (count($product['combinations'])) {
                    $gift_product_attribute_select .= '<select class="id_product_attribute" id="ipa_' . $product['id_product'] . '" name="ipa_' . $product['id_product'] . '">';
                    foreach ($product['combinations'] as $combination) {
                        $gift_product_attribute_select .= '
						<option ' . ($combination['id_product_attribute'] == $current_object->gift_product_attribute ? 'selected="selected"' : '') . ' value="' . $combination['id_product_attribute'] . '">
							' . $combination['attributes'] . ' - ' . $combination['formatted_price'] . '
						</option>';
                    }
                    $gift_product_attribute_select .= '</select>';
                }
            }
        }
        $product = new Product($current_object->gift_product);
        $this->context->smarty->assign(array('show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => $this->toolbar_scroll, 'title' => array($this->l('Payment: '), $this->l('Cart Rules')), 'defaultDateFrom' => date('Y-m-d H:00:00'), 'defaultDateTo' => date('Y-m-d H:00:00', strtotime('+1 month')), 'customerFilter' => $customer_filter, 'giftProductFilter' => $gift_product_filter, 'gift_product_select' => $gift_product_select, 'gift_product_attribute_select' => $gift_product_attribute_select, 'reductionProductFilter' => $reduction_product_filter, 'defaultCurrency' => Configuration::get('PS_CURRENCY_DEFAULT'), 'id_lang_default' => Configuration::get('PS_LANG_DEFAULT'), 'languages' => $languages, 'currencies' => $currencies, 'countries' => $countries, 'carriers' => $carriers, 'groups' => $groups, 'shops' => $shops, 'cart_rules' => $cart_rules, 'product_rule_groups' => $product_rule_groups, 'product_rule_groups_counter' => count($product_rule_groups), 'attribute_groups' => $attribute_groups, 'currentIndex' => self::$currentIndex, 'currentToken' => $this->token, 'currentObject' => $current_object, 'currentTab' => $this, 'hasAttribute' => $product->hasAttributes()));
        $this->content .= $this->createTemplate('form.tpl')->fetch();
        $this->addJqueryUI('ui.datepicker');
        return parent::renderForm();
    }
Exemplo n.º 9
0
 public function getContent()
 {
     $this->html = '';
     if (Tools::isSubmit('submitNetEven')) {
         if (Tools::getValue('NETEVEN_LOGIN') && Tools::getValue('NETEVEN_PASSWORD')) {
             Gateway::updateConfig('NETEVEN_LOGIN', Tools::getValue('NETEVEN_LOGIN'));
             Gateway::updateConfig('NETEVEN_PASSWORD', Tools::getValue('NETEVEN_PASSWORD'));
             Gateway::updateConfig('COMMENT', Tools::getValue('COMMENT'));
             Gateway::updateConfig('DEFAULT_BRAND', Tools::getValue('DEFAULT_BRAND'));
             Gateway::updateConfig('IMAGE_TYPE_NAME', Tools::getValue('IMAGE_TYPE_NAME'));
             Gateway::updateConfig('SYNCHRONISATION_ORDER', (int) Tools::getValue('SYNCHRONISATION_ORDER'));
             Gateway::updateConfig('SYNCHRONISATION_PRODUCT', (int) Tools::getValue('SYNCHRONISATION_PRODUCT'));
             Gateway::updateConfig('TYPE_SKU', (string) Tools::getValue('TYPE_SKU'));
             $this->html .= $this->displayConfirmation($this->l('Les paramètres ont bien été mis à jour'));
         } else {
             $this->html .= $this->displayError($this->l('Les login et mot de passe NetEven sont obligatoire'));
         }
     } elseif (Tools::isSubmit('submitNetEvenShipping')) {
         Gateway::updateConfig('SHIPPING_DELAY', Tools::getValue('SHIPPING_DELAY'));
         Gateway::updateConfig('SHIPPING_PRICE_LOCAL', Tools::getValue('SHIPPING_PRICE_LOCAL'));
         Gateway::updateConfig('SHIPPING_PRICE_INTERNATIONAL', Tools::getValue('SHIPPING_PRICE_INTERNATIONAL'));
         Gateway::updateConfig('SHIPPING_BY_PRODUCT', (int) Tools::getValue('SHIPPING_BY_PRODUCT'));
         Gateway::updateConfig('SHIPPING_BY_PRODUCT_FIELDNAME', Tools::getValue('SHIPPING_BY_PRODUCT_FIELDNAME'));
         Gateway::updateConfig('SHIPPING_CARRIER_FRANCE', Tools::getValue('SHIPPING_CARRIER_FRANCE'));
         Gateway::updateConfig('SHIPPING_ZONE_FRANCE', Tools::getValue('SHIPPING_ZONE_FRANCE'));
         Gateway::updateConfig('SHIPPING_CARRIER_INTERNATIONAL', Tools::getValue('SHIPPING_CARRIER_INTERNATIONAL'));
         Gateway::updateConfig('SHIPPING_ZONE_INTERNATIONAL', Tools::getValue('SHIPPING_ZONE_INTERNATIONAL'));
         $this->html .= $this->displayConfirmation($this->l('Les paramètres de livraison ont bien été mis à jour'));
     } elseif (Tools::isSubmit('submitDev')) {
         Gateway::updateConfig('NETEVEN_URL', Tools::getValue('NETEVEN_URL'));
         Gateway::updateConfig('NETEVEN_NS', Tools::getValue('NETEVEN_NS'));
         Gateway::updateConfig('MAIL_LIST_ALERT', Tools::getValue('MAIL_LIST_ALERT'));
         Gateway::updateConfig('DEBUG', (int) Tools::getValue('DEBUG'));
         Gateway::updateConfig('SEND_REQUEST_BY_EMAIL', (int) Tools::getValue('SEND_REQUEST_BY_EMAIL'));
         $this->html .= $this->displayConfirmation($this->l('Les paramètres de maintenance ont bien été mis à jour'));
     } elseif (Tools::isSubmit('submitCustomizableFeilds')) {
         $customizable_field_name = Tools::getValue('customizable_field_name');
         $customizable_field_value = Tools::getValue('customizable_field_value');
         $customizable_string = '';
         foreach ($customizable_field_name as $key => $value) {
             if (!$customizable_field_name[$key] || !$customizable_field_value[$key]) {
                 continue;
             }
             if ($customizable_string) {
                 $customizable_string .= '¤';
             }
             $customizable_string .= $customizable_field_name[$key] . '|' . $customizable_field_value[$key];
         }
         Gateway::updateConfig('CUSTOMIZABLE_FIELDS', $customizable_string);
     }
     // Lists of order status
     $order_states = OrderState::getOrderStates((int) $this->context->cookie->id_lang);
     // Lists of features
     $features = Feature::getFeatures((int) $this->context->cookie->id_lang);
     // Lists of attribute groups
     $attribute_groups = AttributeGroup::getAttributesGroups((int) $this->context->cookie->id_lang);
     $neteven_features = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'orders_gateway_feature`');
     $neteven_feature_categories = array();
     foreach ($neteven_features as $neteven_feature) {
         if (!isset($neteven_feature_categories[$neteven_feature['category']])) {
             $neteven_feature_categories[$neteven_feature['category']] = array();
         }
         $neteven_feature_categories[$neteven_feature['category']][] = $neteven_feature;
     }
     if ($this->getSOAP()) {
         $this->html .= $this->displayForm($order_states, $features, $attribute_groups, $neteven_feature_categories);
     } else {
         $this->html .= $this->displayError($this->l('This module requires the SOAP extension to run'));
     }
     return $this->html;
 }
 public function ajaxProcessUpdateGroupsPositions()
 {
     $way = (int) Tools::getValue('way');
     $id_attribute_group = (int) Tools::getValue('id_attribute_group');
     $positions = Tools::getValue('attribute_group');
     $new_positions = array();
     foreach ($positions as $k => $v) {
         if (count(explode('_', $v)) == 4) {
             $new_positions[] = $v;
         }
     }
     foreach ($new_positions as $position => $value) {
         $pos = explode('_', $value);
         if (isset($pos[2]) && (int) $pos[2] === $id_attribute_group) {
             if ($group_attribute = new AttributeGroup((int) $pos[2])) {
                 if (isset($position) && $group_attribute->updatePosition($way, $position)) {
                     echo 'ok position ' . (int) $position . ' for group attribute ' . (int) $pos[2] . '\\r\\n';
                 } else {
                     echo '{"hasError" : true, "errors" : "Can not update group attribute ' . (int) $id_attribute_group . ' to position ' . (int) $position . ' "}';
                 }
             } else {
                 echo '{"hasError" : true, "errors" : "This group attribute (' . (int) $id_attribute_group . ') can t be loaded"}';
             }
             break;
         }
     }
 }
Exemplo n.º 11
0
<?php

if (Tools::Q('saveAttributeGroup') == 'add') {
    $attribute_group = new AttributeGroup();
    $attribute_group->copyFromPost();
    $attribute_group->add();
    if (is_array($attribute_group->_errors) and count($attribute_group->_errors) > 0) {
        $errors = $attribute_group->_errors;
    } else {
        $_GET['id'] = $attribute_group->id;
        UIAdminAlerts::conf('已添加属性组');
    }
}
if (isset($_GET['id'])) {
    $id = (int) Tools::G('id');
    $obj = new AttributeGroup($id);
}
if (Tools::Q('saveAttributeGroup') == 'edit') {
    if (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        $obj->update();
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
        $errors = $obj->_errors;
    } else {
        UIAdminAlerts::conf('已更新属性组');
    }
}
if (isset($errors)) {
    UIAdminAlerts::MError($errors);
}
Exemplo n.º 12
0
    protected function attributeImportOne($info, $default_language, &$groups, &$attributes, $regenerate, $shop_is_feature_active, $validateOnly = false)
    {
        AdminImportController::setDefaultValues($info);
        if (!$shop_is_feature_active) {
            $info['shop'] = 1;
        } elseif (!isset($info['shop']) || empty($info['shop'])) {
            $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
        }
        // Get shops for each attributes
        $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
        $id_shop_list = array();
        if (is_array($info['shop']) && count($info['shop'])) {
            foreach ($info['shop'] as $shop) {
                if (!empty($shop) && !is_numeric($shop)) {
                    $id_shop_list[] = Shop::getIdByName($shop);
                } elseif (!empty($shop)) {
                    $id_shop_list[] = $shop;
                }
            }
        }
        if (isset($info['id_product']) && $info['id_product']) {
            $product = new Product((int) $info['id_product'], false, $default_language);
        } elseif (Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) {
            $datas = Db::getInstance()->getRow('
				SELECT p.`id_product`
				FROM `' . _DB_PREFIX_ . 'product` p
				' . Shop::addSqlAssociation('product', 'p') . '
				WHERE p.`reference` = "' . pSQL($info['product_reference']) . '"
			', false);
            if (isset($datas['id_product']) && $datas['id_product']) {
                $product = new Product((int) $datas['id_product'], false, $default_language);
            }
        } else {
            return;
        }
        $id_image = array();
        if (isset($info['image_url']) && $info['image_url']) {
            $info['image_url'] = explode($this->multiple_value_separator, $info['image_url']);
            if (is_array($info['image_url']) && count($info['image_url'])) {
                foreach ($info['image_url'] as $key => $url) {
                    $url = trim($url);
                    $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
                    $image = new Image();
                    $image->id_product = (int) $product->id;
                    $image->position = Image::getHighestPosition($product->id) + 1;
                    $image->cover = !$product_has_images ? true : false;
                    if (isset($info['image_alt'])) {
                        $alt = self::split($info['image_alt']);
                        if (isset($alt[$key]) && strlen($alt[$key]) > 0) {
                            $alt = self::createMultiLangField($alt[$key]);
                            $image->legend = $alt;
                        }
                    }
                    $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
                    $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
                    if ($field_error === true && $lang_field_error === true && !$validateOnly && $image->add()) {
                        $image->associateTo($id_shop_list);
                        // FIXME: 2s/image !
                        if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) {
                            $this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url);
                            $image->delete();
                        } else {
                            $id_image[] = (int) $image->id;
                        }
                        // until here
                    } else {
                        if (!$validateOnly) {
                            $this->warnings[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
                        }
                        if ($field_error !== true || $lang_field_error !== true) {
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
                        }
                    }
                }
            }
        } elseif (isset($info['image_position']) && $info['image_position']) {
            $info['image_position'] = explode($this->multiple_value_separator, $info['image_position']);
            if (is_array($info['image_position']) && count($info['image_position'])) {
                foreach ($info['image_position'] as $position) {
                    // choose images from product by position
                    $images = $product->getImages($default_language);
                    if ($images) {
                        foreach ($images as $row) {
                            if ($row['position'] == (int) $position) {
                                $id_image[] = (int) $row['id_image'];
                                break;
                            }
                        }
                    }
                    if (empty($id_image)) {
                        $this->warnings[] = sprintf($this->trans('No image was found for combination with id_product = %s and image position = %s.', array(), 'Admin.Parameters.Notification'), $product->id, (int) $position);
                    }
                }
            }
        }
        $id_attribute_group = 0;
        // groups
        $groups_attributes = array();
        if (isset($info['group'])) {
            foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
                if (empty($group)) {
                    continue;
                }
                $tab_group = explode(':', $group);
                $group = trim($tab_group[0]);
                if (!isset($tab_group[1])) {
                    $type = 'select';
                } else {
                    $type = trim($tab_group[1]);
                }
                // sets group
                $groups_attributes[$key]['group'] = $group;
                // if position is filled
                if (isset($tab_group[2])) {
                    $position = trim($tab_group[2]);
                } else {
                    $position = false;
                }
                if (!isset($groups[$group])) {
                    $obj = new AttributeGroup();
                    $obj->is_color_group = false;
                    $obj->group_type = pSQL($type);
                    $obj->name[$default_language] = $group;
                    $obj->public_name[$default_language] = $group;
                    $obj->position = !$position ? AttributeGroup::getHigherPosition() + 1 : $position;
                    if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                        // here, cannot avoid attributeGroup insertion to avoid an error during validation step.
                        //if (!$validateOnly) {
                        $obj->add();
                        $obj->associateTo($id_shop_list);
                        $groups[$group] = $obj->id;
                        //}
                    } else {
                        $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
                    }
                    // fills groups attributes
                    $id_attribute_group = $obj->id;
                    $groups_attributes[$key]['id'] = $id_attribute_group;
                } else {
                    // already exists
                    $id_attribute_group = $groups[$group];
                    $groups_attributes[$key]['id'] = $id_attribute_group;
                }
            }
        }
        // inits attribute
        $id_product_attribute = 0;
        $id_product_attribute_update = false;
        $attributes_to_add = array();
        // for each attribute
        if (isset($info['attribute'])) {
            foreach (explode($this->multiple_value_separator, $info['attribute']) as $key => $attribute) {
                if (empty($attribute)) {
                    continue;
                }
                $tab_attribute = explode(':', $attribute);
                $attribute = trim($tab_attribute[0]);
                // if position is filled
                if (isset($tab_attribute[1])) {
                    $position = trim($tab_attribute[1]);
                } else {
                    $position = false;
                }
                if (isset($groups_attributes[$key])) {
                    $group = $groups_attributes[$key]['group'];
                    if (!isset($attributes[$group . '_' . $attribute]) && count($groups_attributes[$key]) == 2) {
                        $id_attribute_group = $groups_attributes[$key]['id'];
                        $obj = new Attribute();
                        // sets the proper id (corresponding to the right key)
                        $obj->id_attribute_group = $groups_attributes[$key]['id'];
                        $obj->name[$default_language] = str_replace('\\n', '', str_replace('\\r', '', $attribute));
                        $obj->position = !$position && isset($groups[$group]) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;
                        if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                            if (!$validateOnly) {
                                $obj->add();
                                $obj->associateTo($id_shop_list);
                                $attributes[$group . '_' . $attribute] = $obj->id;
                            }
                        } else {
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
                        }
                    }
                    $info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int) $info['minimal_quantity'] : 1;
                    $info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']);
                    $info['price'] = str_replace(',', '.', $info['price']);
                    $info['ecotax'] = str_replace(',', '.', $info['ecotax']);
                    $info['weight'] = str_replace(',', '.', $info['weight']);
                    $info['available_date'] = Validate::isDate($info['available_date']) ? $info['available_date'] : null;
                    if (!Validate::isEan13($info['ean13'])) {
                        $this->warnings[] = sprintf($this->trans('EAN13 "%1s" has incorrect value for product with id %2d.', array(), 'Admin.Parameters.Notification'), $info['ean13'], $product->id);
                        $info['ean13'] = '';
                    }
                    if ($info['default_on'] && !$validateOnly) {
                        $product->deleteDefaultAttributes();
                    }
                    // if a reference is specified for this product, get the associate id_product_attribute to UPDATE
                    if (isset($info['reference']) && !empty($info['reference'])) {
                        $id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference']));
                        // updates the attribute
                        if ($id_product_attribute && !$validateOnly) {
                            // gets all the combinations of this product
                            $attribute_combinations = $product->getAttributeCombinations($default_language);
                            foreach ($attribute_combinations as $attribute_combination) {
                                if ($id_product_attribute && in_array($id_product_attribute, $attribute_combination)) {
                                    // FIXME: ~3s/declinaison
                                    $product->updateAttribute($id_product_attribute, (double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, $id_image, strval($info['reference']), strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $info['available_date'], null, $id_shop_list);
                                    $id_product_attribute_update = true;
                                    if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) {
                                        $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']);
                                    }
                                    // until here
                                }
                            }
                        }
                    }
                    // if no attribute reference is specified, creates a new one
                    if (!$id_product_attribute && !$validateOnly) {
                        $id_product_attribute = $product->addCombinationEntity((double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, (int) $info['quantity'], $id_image, strval($info['reference']), 0, strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $id_shop_list, $info['available_date']);
                        if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) {
                            $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']);
                        }
                    }
                    // fills our attributes array, in order to add the attributes to the product_attribute afterwards
                    if (isset($attributes[$group . '_' . $attribute])) {
                        $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute];
                    }
                    // after insertion, we clean attribute position and group attribute position
                    if (!$validateOnly) {
                        $obj = new Attribute();
                        $obj->cleanPositions((int) $id_attribute_group, false);
                        AttributeGroup::cleanPositions();
                    }
                }
            }
        }
        $product->checkDefaultAttributes();
        if (!$product->cache_default_attribute && !$validateOnly) {
            Product::updateDefaultAttribute($product->id);
        }
        if ($id_product_attribute) {
            if (!$validateOnly) {
                // now adds the attributes in the attribute_combination table
                if ($id_product_attribute_update) {
                    Db::getInstance()->execute('
						DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination
						WHERE id_product_attribute = ' . (int) $id_product_attribute);
                }
                foreach ($attributes_to_add as $attribute_to_add) {
                    Db::getInstance()->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute)
						VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')', false);
                }
            }
            // set advanced stock managment
            if (isset($info['advanced_stock_management'])) {
                if ($info['advanced_stock_management'] != 1 && $info['advanced_stock_management'] != 0) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $info['advanced_stock_management'] == 1) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } elseif (!$validateOnly) {
                    $product->setAdvancedStockManagement($info['advanced_stock_management']);
                }
                // automaticly disable depends on stock, if a_s_m set to disabled
                if (!$validateOnly && StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) {
                    StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute);
                }
            }
            // Check if warehouse exists
            if (isset($info['warehouse']) && $info['warehouse']) {
                if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse is not set on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } else {
                    if (Warehouse::exists($info['warehouse'])) {
                        $warehouse_location_entity = new WarehouseProductLocation();
                        $warehouse_location_entity->id_product = $product->id;
                        $warehouse_location_entity->id_product_attribute = $id_product_attribute;
                        $warehouse_location_entity->id_warehouse = $info['warehouse'];
                        if (!$validateOnly) {
                            if (WarehouseProductLocation::getProductLocation($product->id, $id_product_attribute, $info['warehouse']) !== false) {
                                $warehouse_location_entity->update();
                            } else {
                                $warehouse_location_entity->save();
                            }
                            StockAvailable::synchronize($product->id);
                        }
                    } else {
                        $this->warnings[] = sprintf($this->trans('Warehouse did not exist, cannot set on product %1$s.', array(), 'Admin.Parameters.Notification'), $product->name[$default_language]);
                    }
                }
            }
            // stock available
            if (isset($info['depends_on_stock'])) {
                if ($info['depends_on_stock'] != 0 && $info['depends_on_stock'] != 1) {
                    $this->warnings[] = sprintf($this->trans('Incorrect value for "Depends on stock" for product %1$s ', array(), 'Admin.Notifications.Error'), $product->name[$default_language]);
                } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['depends_on_stock'] == 1) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot set "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language]);
                } elseif (!$validateOnly) {
                    StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute);
                }
                // This code allows us to set qty and disable depends on stock
                if (isset($info['quantity']) && (int) $info['quantity']) {
                    // if depends on stock and quantity, add quantity to stock
                    if ($info['depends_on_stock'] == 1) {
                        $stock_manager = StockManagerFactory::getManager();
                        $price = str_replace(',', '.', $info['wholesale_price']);
                        if ($price == 0) {
                            $price = 1.0E-6;
                        }
                        $price = round(floatval($price), 6);
                        $warehouse = new Warehouse($info['warehouse']);
                        if (!$validateOnly && $stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, (int) $info['quantity'], 1, $price, true)) {
                            StockAvailable::synchronize((int) $product->id);
                        }
                    } elseif (!$validateOnly) {
                        if ($shop_is_feature_active) {
                            foreach ($id_shop_list as $shop) {
                                StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop);
                            }
                        } else {
                            StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id);
                        }
                    }
                }
            } elseif (!$validateOnly) {
                // if not depends_on_stock set, use normal qty
                if ($shop_is_feature_active) {
                    foreach ($id_shop_list as $shop) {
                        StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop);
                    }
                } else {
                    StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id);
                }
            }
        }
    }
 public function initContentForCombinations()
 {
     ${${"GLOBALS"}["vmqqtmkyw"]} = $this->object;
     if (!Combination::isFeatureActive()) {
         $this->displayWarning($this->getMessage("This feature has been disabled, you can activate this feature at this page:") . $this->getMessage("link to Performances"));
         return;
     }
     ${"GLOBALS"}["weevwwkl"] = "product";
     if (Validate::isLoadedObject(${${"GLOBALS"}["weevwwkl"]})) {
         self::$smarty->assign("country_display_tax_label", $this->context->country->display_tax_label);
         $zsahvowoo = "lang";
         self::$smarty->assign("tax_exclude_taxe_option", Tax::excludeTaxeOption());
         self::$smarty->assign("id_tax_rules_group", $product->id_tax_rules_group);
         self::$smarty->assign("tax_rules_groups", TaxRulesGroup::getTaxRulesGroups(true));
         ${$zsahvowoo} = new Language($this->id_language);
         self::$smarty->assign("iso_code", $lang->iso_code);
         self::$smarty->assign("combinationImagesJs", $this->getCombinationImagesJs());
         if ($product->is_virtual) {
             $tpkpvyor = "product";
             self::$smarty->assign("product", ${$tpkpvyor});
             $this->displayWarning($this->getMessage("A virtual product cannot have combinations."));
         } else {
             ${"GLOBALS"}["qqjbnscylsi"] = "attribute_js";
             ${"GLOBALS"}["nqxaoftbn"] = "attribute";
             $bcesaxqdqqq = "images";
             ${"GLOBALS"}["zcxmuajd"] = "ps_stock_mvt_reason_default";
             $vmytjghdfi = "attribute_js";
             $nrkrfhirkx = "attributes";
             ${${"GLOBALS"}["qqjbnscylsi"]} = array();
             $cappytc = "k";
             ${"GLOBALS"}["jyaoxpe"] = "attribute";
             ${$nrkrfhirkx} = Attribute::getAttributes($this->context->language->id, true);
             foreach (${${"GLOBALS"}["ecblflvypvt"]} as ${$cappytc} => ${${"GLOBALS"}["jyaoxpe"]}) {
                 ${$vmytjghdfi}[${${"GLOBALS"}["iixdipeiyldv"]}["id_attribute_group"]][${${"GLOBALS"}["iixdipeiyldv"]}["id_attribute"]] = ${${"GLOBALS"}["nqxaoftbn"]}["name"];
             }
             ${"GLOBALS"}["higiwiyuxd"] = "k";
             ${${"GLOBALS"}["sxexnhlq"]} = new Currency((int) Configuration::get("PS_CURRENCY_DEFAULT"));
             self::$smarty->assign("attributeJs", ${${"GLOBALS"}["xenfvrjowsy"]});
             self::$smarty->assign("attributes_groups", AttributeGroup::getAttributesGroups($this->context->language->id));
             self::$smarty->assign("currency", ${${"GLOBALS"}["sxexnhlq"]});
             ${"GLOBALS"}["xzqtsdnlkv"] = "images";
             ${$bcesaxqdqqq} = Image::getImages($this->context->language->id, $product->id);
             self::$smarty->assign("tax_exclude_option", Tax::excludeTaxeOption());
             $rbxbrbxg = "product";
             self::$smarty->assign("ps_weight_unit", Configuration::get("PS_WEIGHT_UNIT"));
             self::$smarty->assign("ps_use_ecotax", Configuration::get("PS_USE_ECOTAX"));
             self::$smarty->assign("field_value_unity", $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "unity"));
             ${"GLOBALS"}["vpcuib"] = "image_type";
             self::$smarty->assign("reasons", ${${"GLOBALS"}["nqegxbae"]} = StockMvtReason::getStockMvtReasons($this->context->language->id));
             self::$smarty->assign("ps_stock_mvt_reason_default", ${${"GLOBALS"}["zcxmuajd"]} = Configuration::get("PS_STOCK_MVT_REASON_DEFAULT"));
             self::$smarty->assign("minimal_quantity", $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "minimal_quantity") ? $this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "minimal_quantity") : 1);
             self::$smarty->assign("available_date", $this->getFieldValue(${$rbxbrbxg}, "available_date") != 0 ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue(${${"GLOBALS"}["vmqqtmkyw"]}, "available_date"), version_compare(_PS_VERSION_, "1.5.5", ">=") ? null : $this->context->language->id))) : "0000-00-00");
             ${${"GLOBALS"}["tqkkuicfgax"]} = 0;
             ${"GLOBALS"}["ucamhp"] = "product";
             self::$smarty->assign("imageType", ImageType::getByNameNType("small_default", "products"));
             self::$smarty->assign("imageWidth", (isset(${${"GLOBALS"}["rvkjjxqs"]}["width"]) ? (int) ${${"GLOBALS"}["vpcuib"]}["width"] : 64) + 25);
             foreach (${${"GLOBALS"}["xzqtsdnlkv"]} as ${${"GLOBALS"}["higiwiyuxd"]} => ${${"GLOBALS"}["inpuwydsyk"]}) {
                 $cshrlmyryz = "image";
                 ${${"GLOBALS"}["dhvuermstcbs"]}[${${"GLOBALS"}["qtxqhylrbsm"]}]["obj"] = new Image(${$cshrlmyryz}["id_image"]);
                 $kcvbkys = "i";
                 ++${$kcvbkys};
             }
             self::$smarty->assign("images", ${${"GLOBALS"}["dhvuermstcbs"]});
             self::$smarty->assign(array("combinationArray" => $this->getCombinations(${${"GLOBALS"}["ucamhp"]}, ${${"GLOBALS"}["sxexnhlq"]}), "product" => ${${"GLOBALS"}["vmqqtmkyw"]}, "id_category" => $product->getDefaultCategory(), "token_generator" => "tokengenerator", "combination_exists" => Shop::isFeatureActive() && Shop::getContextShopGroup()->share_stock && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0));
         }
     } else {
         self::$smarty->assign("product", ${${"GLOBALS"}["vmqqtmkyw"]});
         $this->displayWarning($this->getMessage("You must save this product before adding combinations."));
     }
 }
Exemplo n.º 14
0
    public function attributeImport()
    {
        $default_language = Configuration::get('PS_LANG_DEFAULT');
        $groups = array();
        foreach (AttributeGroup::getAttributesGroups($default_language) as $group) {
            $groups[$group['name']] = (int) $group['id_attribute_group'];
        }
        $attributes = array();
        foreach (Attribute::getAttributes($default_language) as $attribute) {
            $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
        }
        $this->receiveTab();
        $handle = $this->openCsvFile();
        AdminImportController::setLocale();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (count($line) == 1 && empty($line[0])) {
                continue;
            }
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            $info = array_map('trim', $info);
            AdminImportController::setDefaultValues($info);
            if (!Shop::isFeatureActive()) {
                $info['shop'] = 1;
            } elseif (!isset($info['shop']) || empty($info['shop'])) {
                $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            // Get shops for each attributes
            $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
            $id_shop_list = array();
            foreach ($info['shop'] as $shop) {
                if (!is_numeric($shop)) {
                    $id_shop_list[] = Shop::getIdByName($shop);
                } else {
                    $id_shop_list[] = $shop;
                }
            }
            if (isset($info['id_product'])) {
                $product = new Product((int) $info['id_product'], false, $default_language);
            } else {
                continue;
            }
            $id_image = null;
            //delete existing images if "delete_existing_images" is set to 1
            if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) {
                $product->deleteImages();
                $this->cache_image_deleted[(int) $product->id] = true;
            }
            if (isset($info['image_url']) && $info['image_url']) {
                $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
                $url = $info['image_url'];
                $image = new Image();
                $image->id_product = (int) $product->id;
                $image->position = Image::getHighestPosition($product->id) + 1;
                $image->cover = !$product_has_images ? true : false;
                $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
                $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
                if ($field_error === true && $lang_field_error === true && $image->add()) {
                    $image->associateTo($id_shop_list);
                    if (!AdminImportController::copyImg($product->id, $image->id, $url)) {
                        $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
                        $image->delete();
                    } else {
                        $id_image = array($image->id);
                    }
                } else {
                    $this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
                    $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
                }
            } elseif (isset($info['image_position']) && $info['image_position']) {
                $images = $product->getImages($default_language);
                if ($images) {
                    foreach ($images as $row) {
                        if ($row['position'] == (int) $info['image_position']) {
                            $id_image = array($row['id_image']);
                            break;
                        }
                    }
                }
                if (!$id_image) {
                    $this->warnings[] = sprintf(Tools::displayError('No image was found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
                }
            }
            $id_attribute_group = 0;
            // groups
            $groups_attributes = array();
            if (isset($info['group'])) {
                foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
                    $tab_group = explode(':', $group);
                    $group = trim($tab_group[0]);
                    if (!isset($tab_group[1])) {
                        $type = 'select';
                    } else {
                        $type = trim($tab_group[1]);
                    }
                    // sets group
                    $groups_attributes[$key]['group'] = $group;
                    // if position is filled
                    if (isset($tab_group[2])) {
                        $position = trim($tab_group[2]);
                    } else {
                        $position = false;
                    }
                    if (!isset($groups[$group])) {
                        $obj = new AttributeGroup();
                        $obj->is_color_group = false;
                        $obj->group_type = pSQL($type);
                        $obj->name[$default_language] = $group;
                        $obj->public_name[$default_language] = $group;
                        $obj->position = !$position ? AttributeGroup::getHigherPosition() + 1 : $position;
                        if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                            $obj->add();
                            $obj->associateTo($id_shop_list);
                            $groups[$group] = $obj->id;
                        } else {
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
                        }
                        // fils groups attributes
                        $id_attribute_group = $obj->id;
                        $groups_attributes[$key]['id'] = $id_attribute_group;
                    } else {
                        $id_attribute_group = $groups[$group];
                        $groups_attributes[$key]['id'] = $id_attribute_group;
                    }
                }
            }
            // inits attribute
            $id_product_attribute = 0;
            $id_product_attribute_update = false;
            $attributes_to_add = array();
            // for each attribute
            if (isset($info['attribute'])) {
                foreach (explode($this->multiple_value_separator, $info['attribute']) as $key => $attribute) {
                    $tab_attribute = explode(':', $attribute);
                    $attribute = trim($tab_attribute[0]);
                    // if position is filled
                    if (isset($tab_attribute[1])) {
                        $position = trim($tab_attribute[1]);
                    } else {
                        $position = false;
                    }
                    if (isset($groups_attributes[$key])) {
                        $group = $groups_attributes[$key]['group'];
                        if (!isset($attributes[$group . '_' . $attribute]) && count($groups_attributes[$key]) == 2) {
                            $id_attribute_group = $groups_attributes[$key]['id'];
                            $obj = new Attribute();
                            // sets the proper id (corresponding to the right key)
                            $obj->id_attribute_group = $groups_attributes[$key]['id'];
                            $obj->name[$default_language] = str_replace('\\n', '', str_replace('\\r', '', $attribute));
                            $obj->position = !$position && isset($groups[$group]) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;
                            if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                                $obj->add();
                                $obj->associateTo($id_shop_list);
                                $attributes[$group . '_' . $attribute] = $obj->id;
                            } else {
                                $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
                            }
                        }
                        $info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int) $info['minimal_quantity'] : 1;
                        $info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']);
                        $info['price'] = str_replace(',', '.', $info['price']);
                        $info['ecotax'] = str_replace(',', '.', $info['ecotax']);
                        $info['weight'] = str_replace(',', '.', $info['weight']);
                        // if a reference is specified for this product, get the associate id_product_attribute to UPDATE
                        if (isset($info['reference']) && !empty($info['reference'])) {
                            $id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference']));
                            // updates the attribute
                            if ($id_product_attribute) {
                                // gets all the combinations of this product
                                $attribute_combinations = $product->getAttributeCombinations($default_language);
                                foreach ($attribute_combinations as $attribute_combination) {
                                    if ($id_product_attribute && in_array($id_product_attribute, $attribute_combination)) {
                                        $product->updateAttribute($id_product_attribute, (double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], $id_image, strval($info['reference']), strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], 0, null, $id_shop_list);
                                        $id_product_attribute_update = true;
                                    }
                                }
                            }
                        }
                        // if no attribute reference is specified, creates a new one
                        if (!$id_product_attribute) {
                            $id_product_attribute = $product->addCombinationEntity((double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], $id_image, strval($info['reference']), 0, strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $id_shop_list);
                        }
                        // fills our attributes array, in order to add the attributes to the product_attribute afterwards
                        if (isset($attributes[$group . '_' . $attribute])) {
                            $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute];
                        }
                        // after insertion, we clean attribute position and group attribute position
                        $obj = new Attribute();
                        $obj->cleanPositions((int) $id_attribute_group, false);
                        AttributeGroup::cleanPositions();
                    }
                }
            }
            $product->checkDefaultAttributes();
            if (!$product->cache_default_attribute) {
                Product::updateDefaultAttribute($product->id);
            }
            if ($id_product_attribute) {
                // now adds the attributes in the attribute_combination table
                if ($id_product_attribute_update) {
                    Db::getInstance()->execute('
						DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination
						WHERE id_product_attribute = ' . (int) $id_product_attribute);
                }
                foreach ($attributes_to_add as $attribute_to_add) {
                    Db::getInstance()->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute)
						VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')');
                }
                StockAvailable::setQuantity($product->id, $id_product_attribute, (int) $info['quantity']);
            }
        }
        $this->closeCsvFile($handle);
    }
    public function displayForm($isMainTab = true)
    {
        global $currentIndex, $cookie;
        parent::displayForm();
        $jsAttributes = self::displayAndReturnAttributeJs();
        $attributesGroups = AttributeGroup::getAttributesGroups((int) $cookie->id_lang);
        $this->product = new Product((int) Tools::getValue('id_product'));
        // JS Init
        echo '<script type="text/javascript">
			i18n_tax_exc = "' . $this->l('Tax Excl.:') . '";
			i18n_tax_inc = "' . $this->l('Tax Incl.:') . '";

			var product_tax = "' . Tax::getProductTaxRate($this->product->id, NULL) . '";

			function calcPrice(element, element_has_tax)
			{
				name = element.attr("name");
				var element_price = element.val().replace(/,/g, ".");
				var other_element_price = "0";

				if (!isNaN(element_price) && element_price > 0)
				{
					if (element_has_tax)
						other_element_price = parseFloat(element_price / ((product_tax / 100) + 1));
					else
						other_element_price = ps_round(parseFloat(element_price * ((product_tax / 100) + 1)), 2);
				}

				$("#related_to_"+name).val(other_element_price);
			}


			$(document).ready(function()
			{
				$(".price_impact").each(function()
				{
					calcPrice($(this), false);
				});
			});
		</script>';
        if (isset($_POST['generate']) and !sizeof($this->_errors)) {
            echo '
			<div class="module_confirmation conf confirm">
				<img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />
				' . sizeof($this->combinations) . ' ' . $this->l('product(s) successfully created.') . '
			</div>';
        }
        echo '
			<script type="text/javascript" src="../js/attributesBack.js"></script>
			<form enctype="multipart/form-data" method="post" id="generator" action="' . $currentIndex . '&&id_product=' . (int) Tools::getValue('id_product') . '&id_category=' . (int) Tools::getValue('id_category') . '&attributegenerator&token=' . Tools::getValue('token') . '">
				<fieldset style="margin-bottom: 35px;"><legend><img src="../img/admin/asterisk.gif" />' . $this->l('Attributes generator') . '</legend>' . $this->l('Add or modify attributes for product:') . ' <b>' . $this->product->name[$cookie->id_lang] . '</b>
					<br /><br />
                    ';
        echo '
                <div style="padding-top:10px; float: left; width: 570px;">
                    <div style="float:left;">
						<label>' . $this->l('Quantity') . '</label>
						<div class="margin-form">
							<input type="text" size="20" name="quantity" value="0"/>
						</div>
						<label>' . $this->l('Reference') . '</label>
						<div class="margin-form">
							<input type="text" size="20" name="reference" value="' . $this->product->reference . '"/>
						</div>
					</div>
					<div style="float:left; text-align:center; margin-left:20px;">
                        <input type="submit" class="button" style="margin-bottom:5px;" name="generate" value="' . $this->l('Generate') . '" /><br />
                        <input type="submit" class="button" name="back" value="' . $this->l('Back to product') . '" />
					</div>
                    <br style="clear:both;" />
                    <div style="margin-top: 15px;">';
        self::displayGroupeTable($jsAttributes, $attributesGroups);
        echo '
                    </div>
                </div>
            <div style="float: left; margin-left: 60px;">
            ';
        self::displayGroupSelect($jsAttributes, $attributesGroups);
        echo '
				<div>
					<p style="text-align: center;">
						<input class="button" type="button" style="margin: 0 0 10px 20px;" value="' . $this->l('Add') . '" class="button" onclick="add_attr_multiple();" />
						<input class="button" type="button" style="margin: 0 0 10px 20px;" value="' . $this->l('Delete') . '" class="button" onclick="del_attr_multiple();" /><br />
						<input type="submit" class="button" name="back" value="' . $this->l('Back to product') . '" />
					</p>
				</div>
			</div>
			<br />
			</fieldset>
		</form>';
    }
Exemplo n.º 16
0
        <?php 
echo $form->textFieldGroup($model, 'name');
?>
    </div>
</div>


<div class="row">
    <?php 
$tree = [];
$selectedAttributes = [];
$model->refresh();
foreach ($model->typeAttributes as $attribute) {
    $selectedAttributes[] = $attribute->id;
}
foreach ((array) AttributeGroup::model()->findAll() as $group) {
    $items = [];
    $groupHasNotSelectedAttribute = false;
    $groupItems = (array) $group->groupAttributes;
    foreach ($groupItems as $item) {
        $selected = in_array($item->id, $selectedAttributes);
        if (!$selected) {
            $groupHasNotSelectedAttribute = true;
        }
        $items[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('attributes[]', $selected, ['value' => $item->id]) . $item->title, null))];
    }
    $tree[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('', count($groupItems) && !$groupHasNotSelectedAttribute, ['class' => 'group-checkbox']) . $group->name, null)), 'children' => $items];
}
foreach ((array) Attribute::model()->findAllByAttributes(['group_id' => null]) as $attribute) {
    $tree[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('attributes[]', in_array($attribute->id, $selectedAttributes), ['value' => $attribute->id]) . $attribute->title, null))];
}
    public function initContent()
    {
        if (!Combination::isFeatureActive()) {
            $this->displayWarning($this->l('This feature has been disabled, you can activate it at:') . '
				<a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->l('Performance') . '</a>');
            return;
        }
        // Init toolbar
        $this->initToolbarTitle();
        $this->initToolbar();
        $this->initGroupTable();
        $js_attributes = AdminAttributeGeneratorController::displayAndReturnAttributeJs();
        $attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id);
        $this->product = new Product((int) Tools::getValue('id_product'));
        $this->context->smarty->assign(array('tax_rates' => $this->product->getTaxesRate(), 'generate' => isset($_POST['generate']) && !count($this->errors), 'combinations_size' => count($this->combinations), 'product_name' => $this->product->name[$this->context->language->id], 'product_reference' => $this->product->reference, 'url_generator' => self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&attributegenerator&token=' . Tools::getValue('token'), 'attribute_groups' => $attribute_groups, 'attribute_js' => $js_attributes, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => true, 'title' => $this->toolbar_title));
    }
Exemplo n.º 18
0
 public function attributeImport()
 {
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     $groups = array();
     foreach (AttributeGroup::getAttributesGroups($defaultLanguage) as $group) {
         $groups[$group['name']] = (int) $group['id_attribute_group'];
     }
     $attributes = array();
     foreach (Attribute::getAttributes($defaultLanguage) as $attribute) {
         $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
     }
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $fsep = (is_null(Tools::getValue('multiple_value_separator')) or trim(Tools::getValue('multiple_value_separator')) == '') ? ',' : Tools::getValue('multiple_value_separator');
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         $info = array_map('trim', $info);
         self::setDefaultValues($info);
         $product = new Product((int) $info['id_product'], false, $defaultLanguage);
         $id_product_attribute = $product->addProductAttribute((double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], null, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int) $info['default_on'], strval($info['upc']));
         foreach (explode($fsep, $info['options']) as $option) {
             list($group, $attribute) = array_map('trim', explode(':', $option));
             if (!isset($groups[$group])) {
                 $obj = new AttributeGroup();
                 $obj->is_color_group = false;
                 $obj->name[$defaultLanguage] = $group;
                 $obj->public_name[$defaultLanguage] = $group;
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $groups[$group] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             if (!isset($attributes[$group . '_' . $attribute])) {
                 $obj = new Attribute();
                 $obj->id_attribute_group = $groups[$group];
                 $obj->name[$defaultLanguage] = $attribute;
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $attributes[$group . '_' . $attribute] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attributes[$group . '_' . $attribute] . ',' . (int) $id_product_attribute . ')');
         }
     }
     $this->closeCsvFile($handle);
 }
 /**
  * Delete several objects from database
  *
  * return boolean Deletion result
  */
 public function deleteSelection($selection)
 {
     /* Also delete Attributes */
     foreach ($selection as $value) {
         $obj = new AttributeGroup($value);
         if (!$obj->delete()) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 20
0
    /**
     * Display form
     *
     * @global string $currentIndex Current URL in order to keep current Tab
     */
    public function displayForm($token = NULL)
    {
        global $currentIndex;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $color = $obj->color ? $obj->color : 0;
        $attributes_groups = AttributeGroup::getAttributesGroups($this->_defaultFormLanguage);
        $strAttributesGroups = '';
        echo '
		<script type="text/javascript">
			var attributesGroups = {';
        foreach ($attributes_groups as $attribute_group) {
            $strAttributesGroups .= '"' . $attribute_group['id_attribute_group'] . '" : ' . $attribute_group['is_color_group'] . ',';
        }
        echo $strAttributesGroups . '};
		</script>
		<form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . ($token ? $token : $this->token) . '" method="post" enctype="multipart/form-data">
		' . ($obj->id ? '<input type="hidden" name="id_attribute" value="' . $obj->id . '" />' : '') . '
			<fieldset><legend><img src="../img/admin/asterisk.gif" />' . $this->l('Attribute') . '</legend>
				<label>' . $this->l('Name:') . ' </label>
				<div class="margin-form">';
        foreach ($this->_languages as $language) {
            echo '
					<div id="name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;">
						<input size="33" type="text" name="name_' . $language['id_lang'] . '" value="' . htmlspecialchars($this->getFieldValue($obj, 'name', (int) $language['id_lang'])) . '" /><sup> *</sup>
						<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
					</div>';
        }
        echo '
				<script type="text/javascript">
					var flag_fields = \'name\';
				</script>';
        $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true);
        echo '
					<div class="clear"></div>
				</div>
				<label>' . $this->l('Group:') . ' </label>
				<div class="margin-form">
					<select name="id_attribute_group" id="id_attribute_group" onchange="showAttributeColorGroup(\'id_attribute_group\', \'colorAttributeProperties\')">';
        foreach ($attributes_groups as $attribute_group) {
            echo '<option value="' . $attribute_group['id_attribute_group'] . '"' . ($this->getFieldValue($obj, 'id_attribute_group') == $attribute_group['id_attribute_group'] ? ' selected="selected"' : '') . '>' . $attribute_group['name'] . '</option>';
        }
        echo '
					</select><sup> *</sup>
				</div>
				<script type="text/javascript" src="../js/jquery/jquery-colorpicker.js"></script>
				<div id="colorAttributeProperties" style="' . ((Validate::isLoadedObject($obj) and $obj->isColorAttribute()) ? 'display: block;' : 'display: none;') . '">
					<label>' . $this->l('Color') . '</label>
					<div class="margin-form">
						<input width="20px" type="color" data-hex="true" class="color mColorPickerInput" name="color" value="' . (Tools::getValue('color', $color) ? htmlentities(Tools::getValue('color', $color)) : '#000000') . '" /> <sup>*</sup>
						<p class="clear">' . $this->l('HTML colors only (e.g.,') . ' "lightblue", "#CC6600")</p>
					</div>
					<label>' . $this->l('Texture:') . ' </label>
					<div class="margin-form">
						<input type="file" name="texture" />
						<p>' . $this->l('Upload color texture from your computer') . '<br />' . $this->l('This will override the HTML color!') . '</p>
					</div>
					<label>' . $this->l('Current texture:') . ' </label>
					<div class="margin-form">
						<p>' . (file_exists(_PS_IMG_DIR_ . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg') ? '<img src="../img/' . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg" alt="" title="" /> <a href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&deleteImage=1"><img src="../img/admin/delete.gif" alt="" title="' . $this->l('Delete') . '" />' . $this->l('Delete') . '</a>' : $this->l('None')) . '</p>
					</div>
				</div>
				' . Module::hookExec('attributeForm', array('id_attribute' => $obj->id)) . '
				<div class="margin-form">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitAddattribute" class="button" />
				</div>
				<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		</form>
		<script>
			showAttributeColorGroup(\'id_attribute_group\', \'colorAttributeProperties\');
		</script>';
    }
Exemplo n.º 21
0
 public function initFormAttributes($product)
 {
     $data = $this->createTemplate($this->tpl_form);
     if (!Combination::isFeatureActive()) {
         $this->displayWarning($this->l('This feature has been disabled. ') . ' <a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->l('Performances') . '</a>');
     } else {
         if (Validate::isLoadedObject($product)) {
             if ($this->product_exists_in_shop) {
                 if ($product->is_virtual) {
                     $data->assign('product', $product);
                     $this->displayWarning($this->l('A virtual product cannot have combinations.'));
                 } else {
                     $attribute_js = array();
                     $attributes = Attribute::getAttributes($this->context->language->id, true);
                     foreach ($attributes as $k => $attribute) {
                         $attribute_js[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
                     }
                     $currency = $this->context->currency;
                     $data->assign('attributeJs', $attribute_js);
                     $data->assign('attributes_groups', AttributeGroup::getAttributesGroups($this->context->language->id));
                     $data->assign('currency', $currency);
                     $images = Image::getImages($this->context->language->id, $product->id);
                     $data->assign('tax_exclude_option', Tax::excludeTaxeOption());
                     $data->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT'));
                     $data->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX'));
                     $data->assign('field_value_unity', $this->getFieldValue($product, 'unity'));
                     $data->assign('reasons', $reasons = StockMvtReason::getStockMvtReasons($this->context->language->id));
                     $data->assign('ps_stock_mvt_reason_default', $ps_stock_mvt_reason_default = Configuration::get('PS_STOCK_MVT_REASON_DEFAULT'));
                     $data->assign('minimal_quantity', $this->getFieldValue($product, 'minimal_quantity') ? $this->getFieldValue($product, 'minimal_quantity') : 1);
                     $data->assign('available_date', $this->getFieldValue($product, 'available_date') != 0 ? stripslashes(htmlentities($this->getFieldValue($product, 'available_date'), $this->context->language->id)) : '0000-00-00');
                     $i = 0;
                     $type = ImageType::getByNameNType('%', 'products', 'height');
                     if (isset($type['name'])) {
                         $data->assign('imageType', $type['name']);
                     } else {
                         $data->assign('imageType', 'small_default');
                     }
                     $data->assign('imageWidth', (isset($image_type['width']) ? (int) $image_type['width'] : 64) + 25);
                     foreach ($images as $k => $image) {
                         $images[$k]['obj'] = new Image($image['id_image']);
                         ++$i;
                     }
                     $data->assign('images', $images);
                     $data->assign($this->tpl_form_vars);
                     $data->assign(array('list' => $this->renderListAttributes($product, $currency), 'product' => $product, 'id_category' => $product->getDefaultCategory(), 'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator'), 'combination_exists' => Shop::isFeatureActive() && Shop::getContextShopGroup()->share_stock && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0 && $product->hasAttributes()));
                 }
             } else {
                 $this->displayWarning($this->l('You must save the product in this shop before adding combinations.'));
             }
         } else {
             $data->assign('product', $product);
             $this->displayWarning($this->l('You must save this product before adding combinations.'));
         }
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
Exemplo n.º 22
0
                                        $.fn.yiiGridView.update('attribute-group-grid');
                                    }
                                    else {
                                        console.log(data.data);
                                    }
                                }
                            });
                        }
                    });
                });

                function changeGroupFilter() {
                    if (!$('#attribute-group-grid').find('a.editable-open')[0]) {
                        $("#Attribute_group_id").val($.fn.yiiGridView.getSelection('attribute-group-grid')).trigger("change");
                    }
                }
            </script>
        </fieldset>
        <?php 
$attributeGroup = new AttributeGroup('search');
$attributeGroup->unsetAttributes();
$this->widget('yupe\\widgets\\CustomGridView', ['id' => 'attribute-group-grid', 'type' => 'condensed', 'dataProvider' => $attributeGroup->search(), 'template' => "{items}\n{multiaction}", 'hideHeader' => true, 'selectableRows' => 1, 'sortableRows' => true, 'sortableAjaxSave' => true, 'sortableAttribute' => 'position', 'sortableAction' => '/store/attributeBackend/sortable', 'actionsButtons' => ['clear' => CHtml::link(Yii::t("StoreModule.store", "Without a group"), '#', ['id' => 'clear-attribute-group-filter', 'class' => 'btn btn-sm btn-default']), 'add' => CHtml::link(Yii::t('YupeModule.yupe', 'Add'), '#', ['id' => 'add-attribute-group', 'class' => 'btn btn-sm btn-success pull-right'])], 'afterAjaxUpdate' => 'js:function(id, data){ changeGroupFilter(); }', 'columns' => [['name' => 'name', 'class' => 'bootstrap.widgets.TbEditableColumn', 'headerHtmlOptions' => ['style' => 'width:500px'], 'editable' => ['type' => 'text', 'url' => ['/store/attributeBackend/inlineEditGroup'], 'title' => Yii::t('StoreModule.store', 'Enter {field}', ['{field}' => mb_strtolower($attributeGroup->getAttributeLabel('name'))]), 'params' => [Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken], 'placement' => 'right']]]]);
?>
    </div>
    <div class="col-sm-8">
        <?php 
$this->widget('yupe\\widgets\\CustomGridView', ['id' => 'attribute-grid', 'type' => 'condensed', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => [['name' => 'group_id', 'value' => '$data->getGroupTitle()', 'filter' => CHtml::activeDropDownList($model, 'group_id', AttributeGroup::model()->getFormattedList(), ['empty' => '', 'class' => 'form-control'])], ['name' => 'name', 'type' => 'raw', 'value' => 'CHtml::link($data->name, array("/store/attributeBackend/update", "id" => $data->id))'], ['name' => 'title', 'type' => 'raw', 'value' => 'CHtml::link($data->title, array("/store/attributeBackend/update", "id" => $data->id))'], ['name' => 'type', 'type' => 'text', 'value' => '$data->getTypeTitle($data->type)', 'filter' => $model->getTypesList()], ['class' => 'yupe\\widgets\\CustomButtonColumn']]]);
?>
    </div>
</div>
 public function initContent()
 {
     if (!Combination::isFeatureActive()) {
         $url = '<a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->trans('Performance', array(), 'Admin.Global') . '</a>';
         $this->displayWarning(sprintf($this->trans('This feature has been disabled. You can activate it here: %s.', array('%s' => $url), 'Admin.Catalog.Notification')));
         return;
     }
     // Init toolbar
     $this->initPageHeaderToolbar();
     $this->initGroupTable();
     $attributes = Attribute::getAttributes(Context::getContext()->language->id, true);
     $attribute_js = array();
     foreach ($attributes as $k => $attribute) {
         $attribute_js[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
     }
     $attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id);
     $this->product = new Product((int) Tools::getValue('id_product'));
     $this->context->smarty->assign(array('tax_rates' => $this->product->getTaxesRate(), 'generate' => isset($_POST['generate']) && !count($this->errors), 'combinations_size' => count($this->combinations), 'product_name' => $this->product->name[$this->context->language->id], 'product_reference' => $this->product->reference, 'url_generator' => self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&attributegenerator&token=' . Tools::getValue('token'), 'attribute_groups' => $attribute_groups, 'attribute_js' => $attribute_js, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => true, 'show_page_header_toolbar' => $this->show_page_header_toolbar, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn));
 }
 protected function generateAttributeGroupData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $new_path = new Sampledatainstall();
     $id_lang = $this->use_lang;
     $f = fopen($new_path->sendPath() . 'output/attribute_groups.vsc', 'w');
     foreach ($this->attribute_groups_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $attribute_groups = AttributeGroup::getAttributesGroups($id_lang);
     if ($attribute_groups) {
         uasort($attribute_groups, array('SampleDataInstall', 'cmp'));
         foreach ($attribute_groups as $attribute_group) {
             foreach ($this->attribute_groups_fields as $field => $array) {
                 $line[$field] = !Tools::isEmpty($attribute_group[$field]) ? $attribute_group[$field] : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
Exemplo n.º 25
0
 public function attributeImport()
 {
     global $cookie;
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     $groups = array();
     foreach (AttributeGroup::getAttributesGroups($defaultLanguage) as $group) {
         $groups[$group['name']] = (int) $group['id_attribute_group'];
     }
     $attributes = array();
     foreach (Attribute::getAttributes($defaultLanguage) as $attribute) {
         $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
     }
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $fsep = (is_null(Tools::getValue('multiple_value_separator')) or trim(Tools::getValue('multiple_value_separator')) == '') ? ',' : Tools::getValue('multiple_value_separator');
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         $info = array_map('trim', $info);
         self::setDefaultValues($info);
         $product = new Product((int) $info['id_product'], false, $defaultLanguage);
         $id_image = null;
         if (isset($info['image_url']) && $info['image_url']) {
             $productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id);
             $url = $info['image_url'];
             $image = new Image();
             $image->id_product = (int) $product->id;
             $image->position = Image::getHighestPosition($product->id) + 1;
             $image->cover = !$productHasImages ? true : false;
             $image->legend = self::createMultiLangField($product->name);
             if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) {
                 if (!self::copyImg($product->id, $image->id, $url)) {
                     $this->_warnings[] = Tools::displayError('Error copying image: ') . $url;
                 } else {
                     $id_image = array($image->id);
                 }
             } else {
                 $this->_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
         } elseif (isset($info['image_position']) && $info['image_position']) {
             $images = $product->getImages($defaultLanguage);
             if ($images) {
                 foreach ($images as $row) {
                     if ($row['position'] == (int) $info['image_position']) {
                         $id_image = array($row['id_image']);
                         break;
                     }
                 }
             }
             if (!$id_image) {
                 $this->_warnings[] = sprintf(Tools::displayError('No image found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
             }
         }
         $id_product_attribute = $product->addProductAttribute((double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int) $info['default_on'], strval($info['upc']));
         foreach (explode($fsep, $info['options']) as $option) {
             list($group, $attribute) = array_map('trim', explode(':', $option));
             if (!isset($groups[$group])) {
                 $obj = new AttributeGroup();
                 $obj->is_color_group = false;
                 $obj->name[$defaultLanguage] = $group;
                 $obj->public_name[$defaultLanguage] = $group;
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $groups[$group] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             if (!isset($attributes[$group . '_' . $attribute])) {
                 $obj = new Attribute();
                 $obj->id_attribute_group = $groups[$group];
                 $obj->name[$defaultLanguage] = str_replace('\\n', '', str_replace('\\r', '', $attribute));
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $attributes[$group . '_' . $attribute] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attributes[$group . '_' . $attribute] . ',' . (int) $id_product_attribute . ')');
         }
     }
     $this->closeCsvFile($handle);
 }
Exemplo n.º 26
0
Arquivo: _form.php Projeto: yupe/yupe
</div>

<?php 
echo $form->errorSummary($model);
?>

<div class='row'>
    <div class="col-sm-4">
        <?php 
echo $form->dropDownListGroup($model, 'type', ['widgetOptions' => ['data' => $model->getTypesList(), 'htmlOptions' => ['empty' => '---', 'id' => 'attribute-type']]]);
?>
    </div>

    <div class="col-sm-4">
        <?php 
echo $form->dropDownListGroup($model, 'group_id', ['widgetOptions' => ['data' => AttributeGroup::model()->getFormattedList(), 'htmlOptions' => ['empty' => '---']]]);
?>
    </div>
</div>


<div class='row'>
    <div class="col-sm-4">
        <?php 
echo $form->textFieldGroup($model, 'title');
?>
    </div>
    <div class="col-sm-4">
        <?php 
echo $form->slugFieldGroup($model, 'name', ['sourceAttribute' => 'title']);
?>
    function displayFormAttributes($obj, $languages, $defaultLanguage)
    {
        global $currentIndex, $cookie;
        $attributeJs = array();
        $attributes = Attribute::getAttributes(intval($cookie->id_lang), true);
        foreach ($attributes as $k => $attribute) {
            $attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
        }
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $attributes_groups = AttributeGroup::getAttributesGroups(intval($cookie->id_lang));
        $images = Image::getImages(intval($cookie->id_lang), $obj->id);
        if ($obj->id) {
            echo '
			<table cellpadding="5">
				<tr>
					<td colspan="2"><b>' . $this->l('Add or modify combinations for this product') . '</b> - 
					&nbsp;<a href="index.php?tab=AdminCatalog&id_product=' . $obj->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&attributegenerator&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/appearance.gif" alt="combinations_generator" class="middle" title="' . $this->l('Product combinations generator') . '" />&nbsp;' . $this->l('Product combinations generator') . '</a>
					</td>
				</tr>
			</table>
			<hr style="width:730px;"><br />
			<table cellpadding="5" style="width:100%">
			<tr>
			  <td style="width:150px" valign="top">' . $this->l('Group:') . '</td>
			  <td style="padding-bottom:5px;"><select name="attribute_group" id="attribute_group" style="width: 200px;" onchange="populate_attrs();">';
            if (isset($attributes_groups)) {
                foreach ($attributes_groups as $k => $attribute_group) {
                    if (isset($attributeJs[$attribute_group['id_attribute_group']])) {
                        echo '
							<option value="' . $attribute_group['id_attribute_group'] . '">
							' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . '&nbsp;&nbsp;</option>';
                    }
                }
            }
            echo '
				</select></td>
		  </tr>
		  <tr>
			  <td style="width:150px" valign="top">' . $this->l('Attribute:') . '</td>
			  <td style="padding-bottom:5px;"><select name="attribute" id="attribute" style="width: 200px;">
			  <option value="0">---</option>
			  </select>
			  <script type="text/javascript" language="javascript">populate_attrs();</script>
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px" valign="top">
			  <input style="width: 140px; margin-bottom: 10px;" type="button" value="' . $this->l('Add') . '" class="button" onclick="add_attr();"/><br />
			  <input style="width: 140px;" type="button" value="' . $this->l('Delete') . '" class="button" onclick="del_attr()"/></td>
			  <td align="left">
				  <select id="product_att_list" name="attribute_combinaison_list[]" multiple="multiple" size="4" style="width: 320px;"></select>
				</td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:730px;"></td></tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Reference:') . '</td>
			  <td style="padding-bottom:5px;">
				<input size="55" type="text" id="attribute_reference" name="attribute_reference" value="" style="width: 130px; margin-right: 44px;" />
				' . $this->l('EAN13:') . '<input size="55" maxlength="13" type="text" id="attribute_ean13" name="attribute_ean13" value="" style="width: 110px; margin-left: 10px;" />
				<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer">&nbsp;</span></span>
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Supplier Reference:') . '</td>
			  <td style="padding-bottom:5px;">
				<input size="55" type="text" id="attribute_supplier_reference" name="attribute_supplier_reference" value="" style="width: 130px; margin-right: 44px;" />
				' . $this->l('Location:') . '<input size="55" type="text" id="attribute_location" name="attribute_location" value="" style="width: 101px; margin-left: 10px;" />
				<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer">&nbsp;</span></span>
			  </td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:730px;"></td></tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Wholesale price:') . '</td>
			  <td style="padding-bottom:5px;">' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input type="text" size="6"  name="attribute_wholesale_price" id="attribute_wholesale_price" value="0.00" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Wholesale price on Information tab') . ')</td>
		  </tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Impact on price:') . '</td>
			  <td colspan="2" style="padding-bottom:5px;">
				<select name="attribute_price_impact" id="attribute_price_impact" style="width: 140px;" onchange="check_impact();">
				  <option value="0">' . $this->l('None') . '</option>
				  <option value="1">' . $this->l('Increase') . '</option>
				  <option value="-1">' . $this->l('Reduction') . '</option>
				</select> <sup>*</sup>
				<span id="span_impact">&nbsp;&nbsp;' . $this->l('of') . '&nbsp;&nbsp;' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '
					<input type="text" size="6" name="attribute_price" id="attribute_price" value="0.00" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');"/>' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
				</span>
			</td>
		  </tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Impact on weight:') . '</td>
			  <td colspan="2" style="padding-bottom:5px;"><select name="attribute_weight_impact" id="attribute_weight_impact" style="width: 140px;" onchange="check_weight_impact();">
			  <option value="0">' . $this->l('None') . '</option>
			  <option value="1">' . $this->l('Increase') . '</option>
			  <option value="-1">' . $this->l('Reduction') . '</option>
			  </select>
			  <span id="span_weight_impact">&nbsp;&nbsp;' . $this->l('of') . '&nbsp;&nbsp;
				<input type="text" size="6" name="attribute_weight" id="attribute_weight" value="0.00" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . '</span></td>
		  </tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Eco-tax:') . '</td>
			  <td style="padding-bottom:5px;">' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input type="text" size="3" name="attribute_ecotax" id="attribute_ecotax" value="0.00" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Eco-tax on Information tab') . ')</td>
		  </tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Quantity:') . '</td>
			  <td style="padding-bottom:5px;"><input type="text" size="3" name="attribute_quantity" id="attribute_quantity" value="1" /> (' . $this->l('overrides Quantity on Information tab') . ')</td>
		  </tr>
			<tr>
				<td colspan="2"><sup>*</sup> ' . $this->l('included tax') . '</td>
			</tr>
		  <tr><td colspan="2"><hr style="width:730px;"></td></tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Image:') . '</td>
			  <td style="padding-bottom:5px;">
				<ul id="id_image_attr">';
            $i = 0;
            $imageType = ImageType::getByNameNType('small', 'products');
            $imageWidth = (isset($imageType['width']) ? intval($imageType['width']) : 64) + 25;
            foreach ($images as $image) {
                echo '<li style="float: left; width: ' . $imageWidth . 'px;"><input type="checkbox" name="id_image_attr[]" value="' . intval($image['id_image']) . '" id="id_image_attr_' . intval($image['id_image']) . '" />
				<label for="id_image_attr_' . intval($image['id_image']) . '" style="float: none;"><img src="../img/p/' . $obj->id . '-' . $image['id_image'] . '-small.jpg" alt="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" title="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" /></label></li>';
                ++$i;
            }
            echo '</ul>
				<img id="pic" alt="" title="" style="display: none; width: 100px; height: 100px; float: left; border: 1px dashed #BBB; margin-left: 20px;" />
			  </td>
		  </tr>
			<tr>
			  <td style="width:150px">' . $this->l('Default:') . '<br /><br /></td>
			  <td style="padding-bottom:5px;">
				<input type="checkbox" name="attribute_default" id="attribute_default" value="1" />&nbsp;' . $this->l('Make the default combination for this product') . '<br /><br />
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px">&nbsp;</td>
			  <td style="padding-bottom:5px;">
				<span style="float: left;"><input type="submit" name="submitProductAttribute" id="submitProductAttribute" value="' . $this->l('Add this combination') . '" class="button" onclick="attr_selectall();" /> </span>
				<span id="ResetSpan" style="float: left; margin-left: 8px; display: none;">
				  <input type="reset" name="ResetBtn" id="ResetBtn" onclick="if (!confirm(\'' . $this->l('Are you sure you want to cancel?', __CLASS__, true, false) . '\')) return;
				  init_elems(); getE(\'submitProductAttribute\').value = \'' . $this->l('Add this attributes group', __CLASS__, true) . '\';
				  getE(\'id_product_attribute\').value = -1; openCloseLayer(\'ResetSpan\');" class="button" value="' . $this->l('Cancel modification') . '" /></span><span style="clear: both;"></span>
			  </td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:730px;"></td></tr>
		  <tr>
			  <td colspan="2">
					<br />
					<table border="0" cellpadding="0" cellspacing="0" class="table" style="width: 600px;">
						<tr>
							<th>' . $this->l('Attributes') . '</th>
							<th>' . $this->l('Price') . '</th>
							<th>' . $this->l('Weight') . '</th>
							<th>' . $this->l('Reference') . '</th>
							<th>' . $this->l('EAN13') . '</th>
							<th class="center">' . $this->l('Quantity') . '</th>
							<th class="center">' . $this->l('Actions') . '</th>
						</tr>';
            if ($obj->id) {
                /* Build attributes combinaisons */
                $combinaisons = $obj->getAttributeCombinaisons(intval($cookie->id_lang));
                $groups = array();
                if (is_array($combinaisons)) {
                    $combinationImages = $obj->getCombinationImages(intval($cookie->id_lang));
                    foreach ($combinaisons as $k => $combinaison) {
                        $combArray[$combinaison['id_product_attribute']]['wholesale_price'] = $combinaison['wholesale_price'];
                        $combArray[$combinaison['id_product_attribute']]['price'] = $combinaison['price'];
                        $combArray[$combinaison['id_product_attribute']]['weight'] = $combinaison['weight'];
                        $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference'];
                        $combArray[$combinaison['id_product_attribute']]['supplier_reference'] = $combinaison['supplier_reference'];
                        $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13'];
                        $combArray[$combinaison['id_product_attribute']]['location'] = $combinaison['location'];
                        $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity'];
                        $combArray[$combinaison['id_product_attribute']]['id_image'] = isset($combinationImages[$combinaison['id_product_attribute']][0]['id_image']) ? $combinationImages[$combinaison['id_product_attribute']][0]['id_image'] : 0;
                        $combArray[$combinaison['id_product_attribute']]['default_on'] = $combinaison['default_on'];
                        $combArray[$combinaison['id_product_attribute']]['ecotax'] = $combinaison['ecotax'];
                        $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']);
                        if ($combinaison['is_color_group']) {
                            $groups[$combinaison['id_attribute_group']] = $combinaison['group_name'];
                        }
                    }
                }
                $irow = 0;
                if (isset($combArray)) {
                    foreach ($combArray as $id_product_attribute => $product_attribute) {
                        $list = '';
                        $jsList = '';
                        foreach ($product_attribute['attributes'] as $attribute) {
                            $list .= addslashes(htmlspecialchars($attribute[0])) . ' - ' . addslashes(htmlspecialchars($attribute[1])) . ', ';
                            $jsList .= '\'' . addslashes(htmlspecialchars($attribute[0])) . ' : ' . addslashes(htmlspecialchars($attribute[1])) . '\', \'' . $attribute[2] . '\', ';
                        }
                        $list = rtrim($list, ', ');
                        $jsList = rtrim($jsList, ', ');
                        $attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false;
                        echo '
						<tr' . ($irow++ % 2 ? ' class="alt_row"' : '') . ($product_attribute['default_on'] ? ' style="background-color:#D1EAEF"' : '') . '>
							<td>' . stripslashes($list) . '</td>
							<td class="right">' . ($currency->format == 1 ? $currency->sign . ' ' : '') . $product_attribute['price'] . ($currency->format == 2 ? ' ' . $currency->sign : '') . '</td>
							<td class="right">' . $product_attribute['weight'] . Configuration::get('PS_WEIGHT_UNIT') . '</td>
							<td class="right">' . $product_attribute['reference'] . '</td>
							<td class="right">' . $product_attribute['ean13'] . '</td>
							<td class="center">' . $product_attribute['quantity'] . '</td>
							<td class="center">
							<a style="cursor: pointer;">
							<img src="../img/admin/edit.gif" alt="' . $this->l('Modify this combination') . '"
							onclick="javascript:fillCombinaison(\'' . $product_attribute['wholesale_price'] . '\', \'' . $product_attribute['price'] . '\', \'' . $product_attribute['weight'] . '\', \'' . $product_attribute['reference'] . '\', \'' . $product_attribute['supplier_reference'] . '\', \'' . $product_attribute['ean13'] . '\',
							\'' . $product_attribute['quantity'] . '\', \'' . ($attrImage ? $attrImage->id : 0) . '\', Array(' . $jsList . '), \'' . $id_product_attribute . '\', \'' . $product_attribute['default_on'] . '\', \'' . $product_attribute['ecotax'] . '\', \'' . $product_attribute['location'] . '\');" /></a>&nbsp;
							<a href="' . $currentIndex . '&deleteProductAttribute&id_product_attribute=' . $id_product_attribute . '&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');">
							<img src="../img/admin/delete.gif" alt="' . $this->l('Delete this combination') . '" /></a></td>
						</tr>';
                    }
                } else {
                    echo '<tr><td colspan="7" align="center"><i>' . $this->l('No combination yet') . '.</i></td></tr>';
                }
            }
            echo '
						</table>
						<br />' . $this->l('The row in blue is the default combination.') . '
						<br />
						' . $this->l('A default combination must be designated for each product.') . '
						</td>
						</tr>
					</table>
					<script type="text/javascript">
						var impact = getE(\'attribute_price_impact\');
						var impact2 = getE(\'attribute_weight_impact\');

						var s_attr_group = document.getElementById(\'span_new_group\');
						var s_attr_name = document.getElementById(\'span_new_attr\');
						var s_impact = document.getElementById(\'span_impact\');
						var s_impact2 = document.getElementById(\'span_weight_impact\');

						init_elems();
					</script>
					<hr style="width:730px;">
					<table cellpadding="5">
						<tr>
							<td class="col-left"><b>' . $this->l('Color picker:') . '</b></td>
							<td style="padding-bottom:5px;">
								<select name="id_color_default">
								<option value="0">' . $this->l('Do not display') . '</option>';
            foreach ($attributes_groups as $k => $attribute_group) {
                if (isset($groups[$attribute_group['id_attribute_group']])) {
                    echo '<option value="' . intval($attribute_group['id_attribute_group']) . '"
												' . (intval($attribute_group['id_attribute_group']) == intval($obj->id_color_default) ? 'selected="selected"' : '') . '>' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . '</option>';
                }
            }
            echo '
								</select>
								&nbsp;&nbsp;<input type="submit" value="' . $this->l('OK') . '" name="submitAdd' . $this->table . '" class="button" />
								&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?tab=AdminAttributesGroups&token=' . Tools::getAdminToken('AdminAttributesGroups' . intval(Tab::getIdFromClassName('AdminAttributesGroups')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/asterisk.gif" alt="" /> ' . $this->l('Color attribute management') . '</a>
								<p >' . $this->l('Active the color choice by selecting a color attribute group.') . '</p>
							</td>
						</tr>
					</table>';
        } else {
            echo '<b>' . $this->l('You must save this product before adding combinations') . '.</b>';
        }
    }
Exemplo n.º 28
0
    public function displayForm()
    {
        global $currentIndex, $cookie;
        $jsAttributes = self::displayAndReturnAttributeJs();
        $attributesGroups = AttributeGroup::getAttributesGroups(intval($cookie->id_lang));
        $this->product = new Product(intval(Tools::getValue('id_product')));
        if (isset($_POST['generate']) and !sizeof($this->_errors)) {
            echo '
			<div class="module_confirmation conf confirm">
				<img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />
				' . sizeof($this->combinations) . ' ' . $this->l('product(s) successfully created.') . '
			</div>';
        }
        echo '
			<script type="text/javascript" src="../js/attributesBack.js"></script>
			<form enctype="multipart/form-data" method="post" id="generator" action=""' . $currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . 'token=' . Tools::getValue('token') . '">
				<fieldset style="margin-bottom: 35px;"><legend><img src="../img/admin/asterisk.gif" />' . $this->l('Attributes generator') . '</legend>' . $this->l('Add or modify attributes for this product:') . '
					<br /><br />
                    ';
        echo '
                <div style="padding-top:10px; float: left; width: 570px;">
                    <div style="float:left;">
						<label>' . $this->l('Quantity:') . '</label>
						<div class="margin-form">
							<input type="text" size="20" name="quantity" value="1"/>
						</div>
						<label>' . $this->l('Reference:') . '</label>
						<div class="margin-form">
							<input type="text" size="20" name="reference" value="' . $this->product->reference . '"/>
						</div>
					</div>
					<div style="float:left; text-align:center; margin-left:20px;">
                        <input type="submit" class="button" style="margin-bottom:5px;" name="generate" value="' . $this->l('Generate') . '" /><br />
                        <input type="submit" class="button" name="back" value="' . $this->l('Back to product') . '" />
					</div>
                    <br style="clear:both;" />
                    <div style="margin-top: 15px;">';
        self::displayGroupeTable($jsAttributes, $attributesGroups);
        echo '
                    </div>
                </div>
            <div style="float: left; margin-left: 60px;">
            ';
        self::displayGroupSelect($jsAttributes, $attributesGroups);
        echo '
				<div>
                    <input class="button" type="button" style="margin-left: 20px;" value="' . $this->l('Add') . '" class="button" onclick="add_attr_multiple();" />
                    <input class="button" type="button" style="margin-left: 20px;" value="' . $this->l('Delete') . '" class="button" onclick="del_attr_multiple();" />
				</div>
			</div>
			<br />
			</fieldset>
		</form>';
    }
    public function displayList()
    {
        global $currentIndex, $cookie;
        echo '<br /><a href="' . $currentIndex . '&add' . $this->table . '&token=' . $this->token . '"><img src="../img/admin/add.gif" border="0" /> <b>' . $this->l('Add attributes group') . '</b></a><br />
		<a href="' . $currentIndex . '&addattribute&token=' . $this->token . '"><img src="../img/admin/add.gif" border="0" /> ' . $this->l('Add attribute') . '</a><br /><br />
		' . $this->l('Click on the group name to view its attributes. Click again to hide them.') . '<br /><br />';
        if ($this->_list === false) {
            Tools::displayError('No elements found');
        }
        $this->displayListHeader();
        echo '<input type="hidden" name="groupid" value="0">';
        if (!sizeof($this->_list)) {
            echo '<tr><td class="center" colspan="' . sizeof($this->_list) . '">' . $this->l('No elements found') . '</td></tr>';
        }
        $irow = 0;
        foreach ($this->_list as $tr) {
            $id = (int) $tr['id_' . $this->table];
            echo '
			<tr' . ($irow++ % 2 ? ' class="alt_row"' : '') . '>
				<td style="vertical-align: top; padding: 4px 0 4px 0" class="center"><input type="checkbox" name="' . $this->table . 'Box[]" value="' . $id . '" class="noborder" /></td>
				<td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#attributes_' . $id . '\').slideToggle();">' . $tr['name'] . '</td>
				<td style="vertical-align: top; padding: 4px 0 4px 0; width: 340px">
					<div id="attributes_' . $id . '" style="display: none">
					<table class="table" cellpadding="0" cellspacing="0">
						<tr>
							<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'attribute' . $id . 'Box[]\', this.checked)" /></th>
							<th width="100%">' . $this->l('Attribute') . '</th>
							<th>' . $this->l('Actions') . '</th>
						</tr>';
            $attributes = AttributeGroup::getAttributes((int) $cookie->id_lang, $id);
            foreach ($attributes as $attribute) {
                echo '
						<tr>
							<td class="center"><input type="checkbox" name="attribute' . $id . 'Box[]" value="' . $attribute['id_attribute'] . '" class="noborder" /></td>
							<td>
								' . ($tr['is_color_group'] ? '<div style="float: left; width: 18px; height: 12px; border: 1px solid #996633; background-color: ' . $attribute['color'] . '; margin-right: 4px;"></div>' : '') . $attribute['name'] . '
							</td>
							<td class="center">
								<a href="' . $currentIndex . '&id_attribute=' . $attribute['id_attribute'] . '&updateattribute&token=' . $this->token . '">
								<img src="../img/admin/edit.gif" border="0" alt="' . $this->l('Edit') . '" title="' . $this->l('Edit') . '" /></a>&nbsp;
								<a href="' . $currentIndex . '&id_attribute=' . $attribute['id_attribute'] . '&deleteattribute&token=' . $this->token . '"
								onclick="return confirm(\'' . $this->l('Delete attribute', __CLASS__, true, false) . ' : ' . $attribute['name'] . '?\');">
								<img src="../img/admin/delete.gif" border="0" alt="' . $this->l('Delete') . '" title="' . $this->l('Delete') . '" /></a>
							</td>
						</tr>';
            }
            echo '
					</table>
					<p><input type="Submit" class="button" name="submitDelattribute" value="' . $this->l('Delete selection') . '"
					onclick="changeFormParam(this.form, \'' . $currentIndex . '\', ' . $id . '); return confirm(\'' . $this->l('Delete selected items?', __CLASS__, true, false) . '\');" /></p>
					</div>
					</td>';
            echo '
				<td style="vertical-align: top; padding: 4px 0 4px 0" class="center">
					<a href="' . $currentIndex . '&id_' . $this->table . '=' . $id . '&update' . $this->table . '&token=' . $this->token . '">
					<img src="../img/admin/edit.gif" border="0" alt="' . $this->l('Edit') . '" title="' . $this->l('Edit') . '" /></a>&nbsp;
					<a href="' . $currentIndex . '&id_' . $this->table . '=' . $id . '&delete' . $this->table . '&token=' . $this->token . '" onclick="return confirm(\'' . $this->l('Delete item', __CLASS__, true, false) . ' : ' . $tr['name'] . '?\');">
					<img src="../img/admin/delete.gif" border="0" alt="' . $this->l('Delete') . '" title="' . $this->l('Delete') . '" /></a>
				</td>
			</tr>';
        }
        $this->displayListFooter();
    }
Exemplo n.º 30
0
    function displayFormAttributes($obj, $languages, $defaultLanguage)
    {
        global $currentIndex, $cookie;
        $attributeJs = array();
        $attributes = Attribute::getAttributes((int) $cookie->id_lang, true);
        foreach ($attributes as $k => $attribute) {
            $attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
        }
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $attributes_groups = AttributeGroup::getAttributesGroups((int) $cookie->id_lang);
        $default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'));
        $images = Image::getImages((int) $cookie->id_lang, $obj->id);
        if ($obj->id) {
            echo '
			<script type="text/javascript">
				$(document).ready(function(){
					$(\'#id_mvt_reason\').change(function(){
						updateMvtStatus($(this).val());
					});
					updateMvtStatus($(this).val());
				});
			</script>
			<table cellpadding="5">
				<tr>
					<td colspan="2"><b>' . $this->l('Add or modify combinations for this product') . '</b> -
					&nbsp;<a href="index.php?tab=AdminCatalog&id_product=' . $obj->id . '&id_category=' . (int) Tools::getValue('id_category') . '&attributegenerator&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/appearance.gif" alt="combinations_generator" class="middle" title="' . $this->l('Product combinations generator') . '" />&nbsp;' . $this->l('Product combinations generator') . '</a>
					</td>
				</tr>
			</table>
			<hr style="width:100%;" /><br />
			<table cellpadding="5" style="width:100%">
			<tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top">' . $this->l('Group:') . '</td>
			  <td style="padding-bottom:5px;"><select name="attribute_group" id="attribute_group" style="width: 200px;" onchange="populate_attrs();">';
            if (isset($attributes_groups)) {
                foreach ($attributes_groups as $k => $attribute_group) {
                    if (isset($attributeJs[$attribute_group['id_attribute_group']])) {
                        echo '
							<option value="' . $attribute_group['id_attribute_group'] . '">
							' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . '&nbsp;&nbsp;</option>';
                    }
                }
            }
            echo '
				</select></td>
		  </tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top">' . $this->l('Attribute:') . '</td>
			  <td style="padding-bottom:5px;"><select name="attribute" id="attribute" style="width: 200px;">
			  <option value="0">---</option>
			  </select>
			  <script type="text/javascript" language="javascript">populate_attrs();</script>
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top">
			  <input style="width: 140px; margin-bottom: 10px;" type="button" value="' . $this->l('Add') . '" class="button" onclick="add_attr();"/><br />
			  <input style="width: 140px;" type="button" value="' . $this->l('Delete') . '" class="button" onclick="del_attr()"/></td>
			  <td align="left">
				  <select id="product_att_list" name="attribute_combinaison_list[]" multiple="multiple" size="4" style="width: 320px;"></select>
				</td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:100%;" /></td></tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Reference:') . '</td>
			  <td style="padding-bottom:5px;">
				<input size="55" type="text" id="attribute_reference" name="attribute_reference" value="" style="width: 130px; margin-right: 44px;" />
				' . $this->l('EAN13:') . '<input size="55" maxlength="13" type="text" id="attribute_ean13" name="attribute_ean13" value="" style="width: 110px; margin-left: 10px; margin-right: 44px;" />
				' . $this->l('UPC:') . '<input size="55" maxlength="12" type="text" id="attribute_upc" name="attribute_upc" value="" style="width: 110px; margin-left: 10px;" />
				<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer">&nbsp;</span></span>
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Supplier Reference:') . '</td>
			  <td style="padding-bottom:5px;">
				<input size="55" type="text" id="attribute_supplier_reference" name="attribute_supplier_reference" value="" style="width: 130px; margin-right: 44px;" />
				' . $this->l('Location:') . '<input size="55" type="text" id="attribute_location" name="attribute_location" value="" style="width: 101px; margin-left: 10px;" />
				<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer">&nbsp;</span></span>
			  </td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:100%;" /></td></tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Wholesale price:') . '</td>
			  <td style="padding-bottom:5px;">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input type="text" size="6"  name="attribute_wholesale_price" id="attribute_wholesale_price" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Wholesale price on Information tab') . ')</td>
		  </tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on price:') . '</td>
			  <td colspan="2" style="padding-bottom:5px;">
				<select name="attribute_price_impact" id="attribute_price_impact" style="width: 140px;" onchange="check_impact(); calcImpactPriceTI();">
				  <option value="0">' . $this->l('None') . '</option>
				  <option value="1">' . $this->l('Increase') . '</option>
				  <option value="-1">' . $this->l('Reduction') . '</option>
				</select>
				<span id="span_impact">&nbsp;&nbsp;' . $this->l('of') . '&nbsp;&nbsp;' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '
					<input type="text" size="6" name="attribute_price" id="attribute_price" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTI();"/>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '');
            if ($default_country->display_tax_label) {
                echo ' ' . $this->l('(tax excl.)') . '<span ' . (Tax::excludeTaxeOption() ? 'style="display:none"' : '') . '> ' . $this->l('or') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '
							<input type="text" size="6" name="attribute_priceTI" id="attribute_priceTI" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTE();"/>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' ' . $this->l('(tax incl.)') . '</span> ' . $this->l('final product price will be set to') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<span id="attribute_new_total_price">0.00</span>' . ($currency->format % 2 == 0 ? $currency->sign . ' ' : '');
            }
            echo '
				</span>
			</td>
		  </tr>
		  <tr>
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on weight:') . '</td>
			  <td colspan="2" style="padding-bottom:5px;"><select name="attribute_weight_impact" id="attribute_weight_impact" style="width: 140px;" onchange="check_weight_impact();">
			  <option value="0">' . $this->l('None') . '</option>
			  <option value="1">' . $this->l('Increase') . '</option>
			  <option value="-1">' . $this->l('Reduction') . '</option>
			  </select>
			  <span id="span_weight_impact">&nbsp;&nbsp;' . $this->l('of') . '&nbsp;&nbsp;
				<input type="text" size="6" name="attribute_weight" id="attribute_weight" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . '</span></td>
		  </tr>
		  <tr id="tr_unit_impact">
			  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on unit price :') . '</td>
			  <td colspan="2" style="padding-bottom:5px;"><select name="attribute_unit_impact" id="attribute_unit_impact" style="width: 140px;" onchange="check_unit_impact();">
			  <option value="0">' . $this->l('None') . '</option>
			  <option value="1">' . $this->l('Increase') . '</option>
			  <option value="-1">' . $this->l('Reduction') . '</option>
			  </select>
			  <span id="span_unit_impact">&nbsp;&nbsp;' . $this->l('of') . '&nbsp;&nbsp;' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '
				<input type="text" size="6" name="attribute_unity" id="attribute_unity" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' / <span id="unity_third">' . $this->getFieldValue($obj, 'unity') . '</span>
			</span></td>
		  </tr>';
            if (Configuration::get('PS_USE_ECOTAX')) {
                echo '
				  <tr>
					  <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Eco-tax:') . '</td>
					  <td style="padding-bottom:5px;">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input type="text" size="3" name="attribute_ecotax" id="attribute_ecotax" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Eco-tax on Information tab') . ')</td>
				  </tr>';
            }
            echo '
		  <tr id="initial_stock_attribute">
				<td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Initial stock:') . '</td>
				<td><input type="text" name="attribute_quantity" size="3" maxlength="10" value="0"/></td>
		  </tr>
		  </tr>
			<tr id="stock_mvt_attribute" style="display:none;">
				<td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Stock movement:') . '</td>
				<td style="padding-bottom:5px;">
					<select id="id_mvt_reason" name="id_mvt_reason">
						<option value="-1">--</option>';
            $reasons = StockMvtReason::getStockMvtReasons((int) $cookie->id_lang);
            foreach ($reasons as $reason) {
                echo '<option rel="' . $reason['sign'] . '" value="' . $reason['id_stock_mvt_reason'] . '" ' . (Configuration::get('PS_STOCK_MVT_REASON_DEFAULT') == $reason['id_stock_mvt_reason'] ? 'selected="selected"' : '') . '>' . $reason['name'] . '</option>';
            }
            echo '</select>
					<input type="text" name="attribute_mvt_quantity" size="3" maxlength="10" value="0"/>&nbsp;&nbsp;
					<span style="display:none;" id="mvt_sign"></span>
					<br />
					<div class="hint clear" style="display: block;width: 70%;">' . $this->l('Choose the reason and enter the quantity that you want to increase or decrease in your stock') . '</div>
				</td>
			</tr>
			<tr>
			<td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Minimum quantity:') . '</td>
				<td style="padding-bottom:5px;">
					<input size="3" maxlength="10" name="attribute_minimal_quantity" id="attribute_minimal_quantity" type="text" value="' . ($this->getFieldValue($obj, 'attribute_minimal_quantity') ? $this->getFieldValue($obj, 'attribute_minimal_quantity') : 1) . '" />
					<p>' . $this->l('The minimum quantity to buy this product (set to 1 to disable this feature)') . '</p>
				</td>
			</tr>
		  <tr style="display:none;" id="attr_qty_stock">
			  <td style="width:150px">' . $this->l('Quantity in stock:') . '</td>
			  <td style="padding-bottom:5px;"><b><span style="display:none;" id="attribute_quantity"></span></b></td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:100%;" /></td></tr>
		  <tr>
			  <td style="width:150px">' . $this->l('Image:') . '</td>
			  <td style="padding-bottom:5px;">
				<ul id="id_image_attr">';
            $i = 0;
            $imageType = ImageType::getByNameNType('small', 'products');
            $imageWidth = (isset($imageType['width']) ? (int) $imageType['width'] : 64) + 25;
            foreach ($images as $image) {
                $imageObj = new Image($image['id_image']);
                echo '<li style="float: left; width: ' . $imageWidth . 'px;"><input type="checkbox" name="id_image_attr[]" value="' . (int) $image['id_image'] . '" id="id_image_attr_' . (int) $image['id_image'] . '" />
				<label for="id_image_attr_' . (int) $image['id_image'] . '" style="float: none;"><img src="' . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-small.jpg" alt="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" title="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" /></label></li>';
                ++$i;
            }
            echo '</ul>
				<img id="pic" alt="" title="" style="display: none; width: 100px; height: 100px; float: left; border: 1px dashed #BBB; margin-left: 20px;" />
			  </td>
		  </tr>
			<tr>
			  <td style="width:150px">' . $this->l('Default:') . '<br /><br /></td>
			  <td style="padding-bottom:5px;">
				<input type="checkbox" name="attribute_default" id="attribute_default" value="1" />&nbsp;' . $this->l('Make this the default combination for this product') . '<br /><br />
			  </td>
		  </tr>
		  <tr>
			  <td style="width:150px">&nbsp;</td>
			  <td style="padding-bottom:5px;">
				<span style="float: left;"><input type="submit" name="submitProductAttribute" id="submitProductAttribute" value="' . $this->l('Add this combination') . '" class="button" onclick="attr_selectall(); this.form.action += \'&addproduct&tabs=3\';" /> </span>
				<span id="ResetSpan" style="float: left; margin-left: 8px; display: none;">
				  <input type="reset" name="ResetBtn" id="ResetBtn" onclick="init_elems(); getE(\'submitProductAttribute\').value = \'' . $this->l('Add this attributes group', __CLASS__, true) . '\';
				  getE(\'id_product_attribute\').value = 0; $(\'#ResetSpan\').slideToggle();" class="button" value="' . $this->l('Cancel modification') . '" /></span><span class="clear"></span>
			  </td>
		  </tr>
		  <tr><td colspan="2"><hr style="width:100%;" /></td></tr>
		  <tr>
			  <td colspan="2">
					<br />
					<table border="0" cellpadding="0" cellspacing="0" class="table">
						<tr>
							<th>' . $this->l('Attributes') . '</th>
							<th>' . $this->l('Impact') . '</th>
							<th>' . $this->l('Weight') . '</th>
							<th>' . $this->l('Reference') . '</th>
							<th>' . $this->l('EAN13') . '</th>
							<th>' . $this->l('UPC') . '</th>
							<th class="center">' . $this->l('Quantity') . '</th>
							<th class="center">' . $this->l('Actions') . '</th>
						</tr>';
            if ($obj->id) {
                /* Build attributes combinaisons */
                $combinaisons = $obj->getAttributeCombinaisons((int) $cookie->id_lang);
                $groups = array();
                if (is_array($combinaisons)) {
                    $combinationImages = $obj->getCombinationImages((int) $cookie->id_lang);
                    foreach ($combinaisons as $k => $combinaison) {
                        $combArray[$combinaison['id_product_attribute']]['wholesale_price'] = $combinaison['wholesale_price'];
                        $combArray[$combinaison['id_product_attribute']]['price'] = $combinaison['price'];
                        $combArray[$combinaison['id_product_attribute']]['weight'] = $combinaison['weight'];
                        $combArray[$combinaison['id_product_attribute']]['unit_impact'] = $combinaison['unit_price_impact'];
                        $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference'];
                        $combArray[$combinaison['id_product_attribute']]['supplier_reference'] = $combinaison['supplier_reference'];
                        $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13'];
                        $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc'];
                        $combArray[$combinaison['id_product_attribute']]['attribute_minimal_quantity'] = $combinaison['minimal_quantity'];
                        $combArray[$combinaison['id_product_attribute']]['location'] = $combinaison['location'];
                        $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity'];
                        $combArray[$combinaison['id_product_attribute']]['id_image'] = isset($combinationImages[$combinaison['id_product_attribute']][0]['id_image']) ? $combinationImages[$combinaison['id_product_attribute']][0]['id_image'] : 0;
                        $combArray[$combinaison['id_product_attribute']]['default_on'] = $combinaison['default_on'];
                        $combArray[$combinaison['id_product_attribute']]['ecotax'] = $combinaison['ecotax'];
                        $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']);
                        if ($combinaison['is_color_group']) {
                            $groups[$combinaison['id_attribute_group']] = $combinaison['group_name'];
                        }
                    }
                }
                $irow = 0;
                if (isset($combArray)) {
                    foreach ($combArray as $id_product_attribute => $product_attribute) {
                        $list = '';
                        $jsList = '';
                        /* In order to keep the same attributes order */
                        asort($product_attribute['attributes']);
                        foreach ($product_attribute['attributes'] as $attribute) {
                            $list .= addslashes(htmlspecialchars($attribute[0])) . ' - ' . addslashes(htmlspecialchars($attribute[1])) . ', ';
                            $jsList .= '\'' . addslashes(htmlspecialchars($attribute[0])) . ' : ' . addslashes(htmlspecialchars($attribute[1])) . '\', \'' . $attribute[2] . '\', ';
                        }
                        $list = rtrim($list, ', ');
                        $jsList = rtrim($jsList, ', ');
                        $attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false;
                        echo '
						<tr' . ($irow++ % 2 ? ' class="alt_row"' : '') . ($product_attribute['default_on'] ? ' style="background-color:#D1EAEF"' : '') . '>
							<td>' . stripslashes($list) . '</td>
							<td class="right">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . $product_attribute['price'] . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . '</td>
							<td class="right">' . $product_attribute['weight'] . Configuration::get('PS_WEIGHT_UNIT') . '</td>
							<td class="right">' . $product_attribute['reference'] . '</td>
							<td class="right">' . $product_attribute['ean13'] . '</td>
							<td class="right">' . $product_attribute['upc'] . '</td>
							<td class="center">' . $product_attribute['quantity'] . '</td>
							<td class="center">
							<a style="cursor: pointer;">
							<img src="../img/admin/edit.gif" alt="' . $this->l('Modify this combination') . '"
							onclick="javascript:fillCombinaison(\'' . $product_attribute['wholesale_price'] . '\', \'' . $product_attribute['price'] . '\', \'' . $product_attribute['weight'] . '\', \'' . $product_attribute['unit_impact'] . '\', \'' . $product_attribute['reference'] . '\', \'' . $product_attribute['supplier_reference'] . '\', \'' . $product_attribute['ean13'] . '\',
							\'' . $product_attribute['quantity'] . '\', \'' . ($attrImage ? $attrImage->id : 0) . '\', Array(' . $jsList . '), \'' . $id_product_attribute . '\', \'' . $product_attribute['default_on'] . '\', \'' . $product_attribute['ecotax'] . '\', \'' . $product_attribute['location'] . '\', \'' . $product_attribute['upc'] . '\', \'' . $product_attribute['attribute_minimal_quantity'] . '\'); calcImpactPriceTI();" /></a>&nbsp;
							' . (!$product_attribute['default_on'] ? '<a href="' . $currentIndex . '&defaultProductAttribute&id_product_attribute=' . $id_product_attribute . '&id_product=' . $obj->id . '&' . (Tools::isSubmit('id_category') ? 'id_category=' . (int) Tools::getValue('id_category') . '&' : '&') . 'token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '">
							<img src="../img/admin/asterisk.gif" alt="' . $this->l('Make this the default combination') . '" title="' . $this->l('Make this combination the default one') . '"></a>' : '') . '
							<a href="' . $currentIndex . '&deleteProductAttribute&id_product_attribute=' . $id_product_attribute . '&id_product=' . $obj->id . '&' . (Tools::isSubmit('id_category') ? 'id_category=' . (int) Tools::getValue('id_category') . '&' : '&') . 'token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');">
							<img src="../img/admin/delete.gif" alt="' . $this->l('Delete this combination') . '" /></a></td>
						</tr>';
                    }
                    echo '<tr><td colspan="7" align="center"><a href="' . $currentIndex . '&deleteAllProductAttributes&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');"><img src="../img/admin/delete.gif" alt="' . $this->l('Delete this combination') . '" /> ' . $this->l('Delete all combinations') . '</a></td></tr>';
                } else {
                    echo '<tr><td colspan="7" align="center"><i>' . $this->l('No combination yet') . '.</i></td></tr>';
                }
            }
            echo '
						</table>
						<br />' . $this->l('The row in blue is the default combination.') . '
						<br />
						' . $this->l('A default combination must be designated for each product.') . '
						</td>
						</tr>
					</table>
					<script type="text/javascript">
						var impact = getE(\'attribute_price_impact\');
						var impact2 = getE(\'attribute_weight_impact\');

						var s_attr_group = document.getElementById(\'span_new_group\');
						var s_attr_name = document.getElementById(\'span_new_attr\');
						var s_impact = document.getElementById(\'span_impact\');
						var s_impact2 = document.getElementById(\'span_weight_impact\');

						init_elems();
					</script>
					<hr style="width:100%;" />
					<table cellpadding="5">
						<tr>
							<td class="col-left"><b>' . $this->l('Color picker:') . '</b></td>
							<td style="padding-bottom:5px;">
								<select name="id_color_default">
								<option value="0">' . $this->l('Do not display') . '</option>';
            foreach ($attributes_groups as $k => $attribute_group) {
                if (isset($groups[$attribute_group['id_attribute_group']])) {
                    echo '<option value="' . (int) $attribute_group['id_attribute_group'] . '"
												' . ((int) $attribute_group['id_attribute_group'] == (int) $obj->id_color_default ? 'selected="selected"' : '') . '>' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . '</option>';
                }
            }
            echo '
								</select>
								&nbsp;&nbsp;<input type="submit" value="' . $this->l('OK') . '" name="submitAdd' . $this->table . 'AndStay" class="button" />
								&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?tab=AdminAttributesGroups&token=' . Tools::getAdminToken('AdminAttributesGroups' . (int) Tab::getIdFromClassName('AdminAttributesGroups') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/asterisk.gif" alt="" /> ' . $this->l('Color attribute management') . '</a>
								<p >' . $this->l('Activate the color choice by selecting a color attribute group.') . '</p>
							</td>
						</tr>
					</table>';
        } else {
            echo '<b>' . $this->l('You must save this product before adding combinations') . '.</b>';
        }
    }