public function add() { $this->shop_id = $this->shop_id ? $this->shop_id : JeproshopContext::getContext()->shop->shop_id; $this->shop_group_id = $this->shop_group_id ? $this->shop_group_id : JeproshopContext::getContext()->shop->shop_group_id; $this->lang_id = $this->lang_id ? $this->lang_id : JeproshopContext::getContext()->language->lang_id; $this->birthday = empty($this->years) ? $this->birthday : (int) $this->years . '-' . (int) $this->months . '-' . (int) $this->days; $this->secure_key = md5(uniqid(rand(), true)); $this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-' . JeproshopSettingModelSetting::getValue('password_regeneration_delay') . ' minutes')); if ($this->newsletter && !JeproshopTools::isDate($this->newsletter_date_add)) { $this->newsletter_date_add = date('Y-m-d H:i:s'); } if ($this->default_group_id == JeproshopSettingModelSetting::getValue('customer_group')) { if ($this->is_guest) { $this->default_group_id = (int) JeproshopSettingModelSetting::getValue('guest_group'); } else { $this->default_group_id = (int) JeproshopSettingModelSetting::getValue('customer_group'); } } /* Can't create a guest customer, if this feature is disabled */ if ($this->is_guest && !JeproshopSettingModelSetting::getValue('enable_guest_checkout')) { return false; } $this->date_add = date('Y-m-d H:i:s'); $this->date_upd = date('Y-m-d H:i:s'); $db = JFactory::getDBO(); $input = JRequest::get('get'); $isNewCustomer = isset($input['is_new_customer']) ? 1 : 0; $email = isset($input['email']) ? $input['email'] : ''; $company = ''; if (!$isNewCustomer) { $password = md5(time() . COM_JEPROSHOP_COOKIE_KEY); } else { $password = md5($input['passwd'] . COM_JEPROSHOP_COOKIE_KEY); } $siret = isset($input['siret']) ? $input['siret'] : ''; $ape = isset($input['ape']) ? $input['ape'] : ''; $title = isset($input['title']) ? $input['title'] : ''; $firstName = isset($input['firstname']) ? $input['firstname'] : ''; $lastName = isset($input['lastname']) ? $input['lastname'] : ''; $deleted = isset($input['deleted']) ? $input['deleted'] : 0; $query = "INSERT INTO " . $db->quoteName('#__jeproshop_customer') . "(" . $db->quoteName('shop_group_id') . ", " . $db->quoteName('shop_id') . ", " . $db->quoteName('default_group_id') . ", " . $db->quoteName('lang_id') . ", "; $query .= $db->quoteName('company') . ", " . $db->quoteName('siret') . ", " . $db->quoteName('ape') . ", " . $db->quoteName('title') . ", " . $db->quoteName('firstname') . ", " . $db->quoteName('lastname') . ", "; $query .= $db->quoteName('email') . ", " . $db->quoteName('passwd') . ", " . $db->quoteName('last_passwd_gen') . ", " . $db->quoteName('secure_key') . ", " . $db->quoteName('published') . ", " . $db->quoteName('is_guest') . ", "; $query .= $db->quoteName('deleted') . ", " . $db->quoteName('date_add') . ", " . $db->quoteName('date_upd') . ") VALUES (" . (int) $this->shop_group_id . ", " . (int) $this->shop_id . ", " . (int) $this->default_group_id . ", "; $query .= (int) $this->lang_id . ", " . $db->quote($company) . ", " . $db->quote($siret) . ", " . $db->quote($ape) . ", " . $db->quote($title) . ", " . $db->quote($firstName) . ", " . $db->quote($lastName) . ", "; $query .= $db->quote($email) . ", " . $db->quote($password) . ", " . $db->quote($this->last_passwd_gen) . ", " . $db->quote($this->secure_key) . ", " . (int) $this->published . ", " . (int) $this->is_guest . ", " . (int) $deleted; $query .= ", " . $db->quote($this->date_add) . ", " . $db->quote($this->date_upd) . ")"; $db->setQuery($query); $success = $db->query(); $this->customer_id = $db->insertid(); $this->updateGroup($this->groupBox); return $success; }
/** * Display date regarding to language preferences * * @param string $date Date to display format UNIX * @param boolean $full With time or not (optional) * @return string Date * @throws JException */ public static function displayDate($date, $full = false) { if (!$date || !($time = strtotime($date))) { return $date; } if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00') { return ''; } if (!JeproshopTools::isDate($date) || !JeproshopTools::isBool($full)) { throw new JException('Invalid date'); } $context = JeproshopContext::getContext(); $date_format = $full ? $context->language->date_format_full : $context->language->date_format_lite; return date($date_format, $time); }
public function update() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $data = JRequest::get('post'); $input_data = $data['jform']; if ($this->context == null) { $this->context = JeproshopContext::getContext(); } $product = new JeproshopProductModelProduct((int) $app->input->get('product_id')); $existing_product = JeproshopTools::isLoadedObject($product, 'product_id'); $this->checkProduct(); if (!empty($this->context->controller->errors)) { $this->context->controller->layout = 'edit'; return false; } $product_id = (int) $app->input->get('product_id'); /* Update an existing product */ if (isset($product_id) && !empty($product_id)) { if (JeproshopTools::isLoadedObject($product, 'product_id')) { $this->removeTaxFromEcotax(); $product_type_before = $product->getType(); //$this->copyFromPost($object, $this->table); $product->indexed = 0; if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() != JeproshopShopModelShop::CONTEXT_SHOP) { $product->setFieldsToUpdate((array) $app->input->get('multishop_check')); } // Duplicate combinations if not associated to shop if ($this->context->shop->getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && !$product->isAssociatedToShop()) { $is_associated_to_shop = false; $combinations = JeproshopProductModelProduct::getProductAttributesIds($product_id); if ($combinations) { foreach ($combinations as $combination_id) { $combination = new JeproshopCombinationModelCombination((int) $combination_id->product_attribute_id); $default_combination = new JeproshopCombinationModelCombination((int) $combination_id->product_attribute_id, null, (int) $this->product->default_shop_id); //$def = ObjectModel::getDefinition($default_combination); $combination->product_id = (int) $default_combination->product_id; $location = JeproshopTools::isGenericName($default_combination->location) ? $default_combination->location : ''; $combination->location = $db->quote($location); $ean13 = JeproshopTools::isEan13($default_combination->ean13) ? $default_combination->ean13 : ''; $combination->ean13 = $db->quote($ean13); $combination->upc = JeproshopTools::isUpc($default_combination->upc) ? $default_combination->upc : ''; $combination->quantity = (int) $default_combination->quantity; $combination->reference = $default_combination->reference; $combination->supplier_reference = $default_combination->supplier_reference; $combination->wholesale_price = (double) $default_combination->wholesale_price; $combination->price = (double) $default_combination->price; $combination->ecotax = (double) $default_combination->ecotax; $combination->weight = (double) $default_combination->weight; $combination->unit_price_impact = (double) $default_combination->unit_price_impact; $combination->minimal_quantity = (int) $default_combination->default_on; $combination->default_on = (int) $default_combination->default_on; $combination->available_date = JeproshopTools::isDate($default_combination->available_date) ? $default_combination->available_date : null; $combination->save(); } } } else { $is_associated_to_shop = true; } if ($product->updateProduct()) { // If the product doesn't exist in the current shop but exists in another shop if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && !$product->isAssociatedToShop($this->context->shop->shop_id)) { $out_of_stock = JeproshopStockAvailableModelStockAvailable::outOfStock($existing_product->product_id, $existing_product->default_shop_id); $depends_on_stock = JeproshopStockAvailableModelStockAvailable::dependsOnStock($existing_product->product_id, $existing_product->default_shop_id); JeproshopStockAvailableModelStockAvailable::setProductOutOfStock((int) $product->product_id, $out_of_stock, $this->context->shop->shop_id); JeproshopStockAvailableModelStockAvailable::setProductDependsOnStock((int) $product->product_id, $depends_on_stock, $this->context->shop->shop_id); } //PrestaShopLogger::addLog(sprintf($this->l('%s edition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id); if (in_array($this->context->shop->getShopContext(), array(JeproshopShopModelShop::CONTEXT_SHOP, JeproshopShopModelShop::CONTEXT_ALL))) { //if ($this->isTabSubmitted('Shipping')) $product->addCarriers(); //if ($this->isTabSubmitted('Associations')) $product->updateAccessories($product); //if ($this->isTabSubmitted('Suppliers')) $product->processSuppliers(); //if ($this->isTabSubmitted('Features')) $product->processFeatures(); //if ($this->isTabSubmitted('Combinations')) $product->processProductAttribute(); //if ($this->isTabSubmitted('Prices')) //{ $product->processPriceAddition(); $product->processSpecificPricePriorities(); //} //if ($this->isTabSubmitted('Customization')) $product->processCustomizationConfiguration(); //if ($this->isTabSubmitted('Attachments')) $product->processAttachments(); $product->updatePackItems(); // Disallow advanced stock management if the product become a pack if ($product_type_before == JeproshopProductModelProduct::SIMPLE_PRODUCT && $product->getType() == JeproshopProductModelProduct::PACKAGE_PRODUCT) { JeproshopStockAvailableModelAVailable::setProductDependsOnStock((int) $product->product_id, false); } $product->updateDownloadProduct(1); $product->updateTags(JeproshopLanguageModelLanguage::getLanguages(false)); if ($product->isProductFieldUpdated('category_box') && !$product->updateCategories($input_data['category_box'])) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('COM_JEPROSHOP_AN_ERROR_OCCURRED_WHILE_LINKING_THE_PRODUCT_TO_THE_CATEGORIES_MESSAGE')); } } //if ($this->isTabSubmitted('Warehouses')) $product->processWarehouses(); if (empty($this->context->controller->errors)) { if (in_array($product->visibility, array('both', 'search')) && JeproshopSettingModelSetting::getValue('search_indexation')) { JeproshopSearch::indexation(false, $product->product_id); } // Save and preview if ($app->input->get('submitAddProductAndPreview')) { $this->redirect_after = $this->getPreviewUrl($product); } else { // Save and stay on same form //if ($this->context->controller->layout == 'edit'){ $message = JText::_('COM_JEPROSHOP_PRODUCT_SUCCESSFULLY_UPDATE_MESSAGE'); $category_id = $app->input->get('category_id'); $app->redirect('index.php?option=com_jeproshop&view=product&product_id=' . (int) $product->product_id . (isset($category_id) ? '&category_id=' . (int) $app->input->get('category_id') : '') . '&task=edit&' . JSession::getFormToken() . '=1', $message); /*}else{ // Default behavior (save and back) $category_id = $app->input->get('category_id'); $app->redirect('index.php?option=com_jeproshop&view=product' . (isset($category_id) ? '&category_id=' . (int)$app->input->get('category_id') : '')); //. self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=4&token='.$this->token; }*/ } } else { // if errors : stay on edit page $this->context->controller->layout = 'edit'; } } else { if (!$is_associated_to_shop && $combinations) { foreach ($combinations as $combination_item) { $combination = new JeproshopCombinationModelCombination((int) $combination_item->product_attribute_id); $combination->delete(); } } $this->context->controller->has_errors = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . '</b> (' . Db::getInstance()->getMsgError() . ')'; } } else { $this->context->controller->has_errors = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . '</b> (' . Tools::displayError('The object cannot be loaded. ') . ')'; } $app->redirect('index.php?option=com_jeproshop&view=product&task=edit&product_id=' . $product_id); } }