Beispiel #1
0
 public function processCustomizationConfiguration()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $product = new JeproshopProductModelProduct($app->input->get('product_id'));
     // Get the number of existing customization fields ($product->text_fields is the updated value, not the existing value)
     $current_customization = $product->getCustomizationFieldIds();
     $files_count = 0;
     $text_count = 0;
     if (is_array($current_customization)) {
         foreach ($current_customization as $field) {
             if ($field->type == 1) {
                 $text_count++;
             } else {
                 $files_count++;
             }
         }
     }
     if (!$product->createLabels((int) $product->uploadable_files - $files_count, (int) $product->text_fields - $text_count)) {
         $this->context->controller->has_errors = Tools::displayError('An error occurred while creating customization fields.');
     }
     if (!$this->context->controller->has_errors && !$product->updateLabels()) {
         $this->context->controller->has_errors = JText::_('An error occurred while updating customization fields.');
     }
     $customizable = $product->uploadable_files > 0 || $product->text_fields > 0 ? 1 : 0;
     $query = "UPDATE " . $db->quoteName('#__jeproshop_product') . " SET " . $db->quoteName('customizable') . " = " . (int) $customizable . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product->product_id;
     $db->setQuery($query);
     $result = $db->query();
     $query = "UPDATE " . $db->quoteName('#__jeproshop_product_shop') . " SET " . $db->quoteName('customizable') . " = " . (int) $customizable . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product->product_id;
     $db->setQuery($query);
     $result &= $db->query();
     if (!$this->context->controller->has_errors && !$result) {
         $this->context->controller->has_errors = true;
         JText::_('An error occurred while updating the custom configuration.' . __FILE__ . ' line ' . __LINE__);
     }
 }