Exemple #1
0
 public static function get($id)
 {
     global $lC_Database, $lC_Language, $lC_Currencies;
     $Qproducts = $lC_Database->query('select p.*, pd.* from :table_products p, :table_products_description pd where p.products_id = :products_id and p.products_id = pd.products_id and pd.language_id = :language_id');
     $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
     $Qproducts->bindInt(':products_id', $id);
     $Qproducts->bindInt(':language_id', $lC_Language->getID());
     $Qproducts->execute();
     $data = array_merge(array('products_id' => $id), (array) $Qproducts->toArray());
     $Qproducts->freeResult();
     $Qspecials = $lC_Database->query('select * from :table_specials where products_id = :products_id');
     $Qspecials->bindTable(':table_specials', TABLE_SPECIALS);
     $Qspecials->bindInt(':products_id', $id);
     $Qspecials->execute();
     $data['products_special_status'] = $Qspecials->valueInt('status');
     $data['products_special_price'] = $Qspecials->valueDecimal('specials_new_products_price');
     if ($Qspecials->value('start_date') != null) {
         $data['products_special_start_date'] = lC_DateTime::getShort($Qspecials->value('start_date'));
     }
     if ($Qspecials->value('expires_date') != null) {
         $data['products_special_expires_date'] = lC_DateTime::getShort($Qspecials->value('expires_date'));
     }
     $Qspecials->freeResult();
     $Qfeatured = $lC_Database->query('select status from :table_featured_products where products_id = :products_id limit 1');
     $Qfeatured->bindTable(':table_featured_products', TABLE_FEATURED_PRODUCTS);
     $Qfeatured->bindInt(':products_id', $id);
     $Qfeatured->execute();
     $data['products_featured'] = $Qfeatured->valueInt('status');
     $Qfeatured->freeResult();
     $variants_array = array();
     if ($data['has_children'] == '1') {
         $QmultiSKUProducts = $lC_Database->query('select * from :table_products where parent_id = :parent_id');
         $QmultiSKUProducts->bindTable(':table_products', TABLE_PRODUCTS);
         $QmultiSKUProducts->bindInt(':parent_id', $data['products_id']);
         $QmultiSKUProducts->execute();
         while ($QmultiSKUProducts->next()) {
             $variants_array[$QmultiSKUProducts->valueInt('products_id')]['data'] = array('cost' => $QmultiSKUProducts->value('products_cost'), 'price' => $QmultiSKUProducts->value('products_price'), 'msrp' => $QmultiSKUProducts->value('products_msrp'), 'tax_class_id' => $QmultiSKUProducts->valueInt('products_tax_class_id'), 'model' => $QmultiSKUProducts->value('products_model'), 'sku' => $QmultiSKUProducts->value('products_sku'), 'quantity' => $QmultiSKUProducts->value('products_quantity'), 'weight' => $QmultiSKUProducts->value('products_weight'), 'weight_class_id' => $QmultiSKUProducts->valueInt('products_weight_class'), 'availability_shipping' => 1, 'status' => $QmultiSKUProducts->valueInt('products_status'));
             $Qvariants = $lC_Database->query('select pv.default_combo, pv.default_visual, pvg.id as group_id, pvg.title as group_title, pvg.module, pvv.id as value_id, pvv.title as value_title, pvv.visual as visual, pvv.sort_order as value_sort_order from :table_products_variants pv, :table_products_variants_groups pvg, :table_products_variants_values pvv where pv.products_id = :products_id and pv.products_variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id order by pvg.sort_order, pvg.title');
             $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
             $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
             $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
             $Qvariants->bindInt(':products_id', $QmultiSKUProducts->valueInt('products_id'));
             $Qvariants->bindInt(':languages_id', $lC_Language->getID());
             $Qvariants->bindInt(':languages_id', $lC_Language->getID());
             $Qvariants->execute();
             while ($Qvariants->next()) {
                 $variants_array[$QmultiSKUProducts->valueInt('products_id')]['values'][$Qvariants->valueInt('group_id')][$Qvariants->valueInt('value_id')] = array('value_id' => $Qvariants->valueInt('value_id'), 'group_title' => $Qvariants->value('group_title'), 'value_title' => $Qvariants->value('value_title'), 'sort_order' => $Qvariants->value('value_sort_order'), 'default' => (bool) $Qvariants->valueInt('default_combo'), 'default_visual' => $Qvariants->valueInt('default_visual'), 'module' => $Qvariants->value('module'), 'visual' => $Qvariants->value('visual'));
             }
         }
         $QmultiSKUProducts->freeResult();
     }
     $data['variants'] = $variants_array;
     $Qattributes = $lC_Database->query('select id, value, value2 from :table_product_attributes where products_id = :products_id and languages_id in (0, :languages_id)');
     $Qattributes->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES);
     $Qattributes->bindInt(':products_id', $id);
     $Qattributes->bindInt(':languages_id', $lC_Language->getID());
     $Qattributes->execute();
     $attributes_array = array();
     $data['attributes2'] = array();
     while ($Qattributes->next()) {
         // if the value is date, reformat for datepicker
         $value = substr($Qattributes->value('value'), 4, 1) == '-' ? lC_DateTime::getShort($Qattributes->value('value')) : $Qattributes->value('value');
         $attributes_array[$Qattributes->valueInt('id')] = $value;
         // check for value2
         if ($Qattributes->value('value2') != null) {
             $data['attributes2'][$Qattributes->valueInt('id')] = $Qattributes->value('value2');
         }
     }
     $data['attributes'] = $attributes_array;
     $Qattributes->freeResult();
     $Qimages = $lC_Database->query('select id, image, default_flag from :table_products_images where products_id = :products_id order by sort_order');
     $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
     $Qimages->bindInt(':products_id', $id);
     $Qimages->execute();
     while ($Qimages->next()) {
         if ($Qimages->valueInt('default_flag') == '1') {
             $data['image'] = $Qimages->value('image');
         }
     }
     $Qimages->freeResult();
     // load subproducts
     $Qsubproducts = $lC_Database->query('select p.*, pd.* from :table_products p, :table_products_description pd where p.parent_id = :products_id and p.products_id = pd.products_id and pd.language_id = :language_id');
     $Qsubproducts->bindTable(':table_products', TABLE_PRODUCTS);
     $Qsubproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
     $Qsubproducts->bindInt(':products_id', $id);
     $Qsubproducts->bindInt(':language_id', $lC_Language->getID());
     $Qsubproducts->execute();
     $subproducts_array = array();
     while ($Qsubproducts->next()) {
         // subproduct images
         $Qimages = $lC_Database->query('select id, image, default_flag from :table_products_images where products_id = :sub_products_id order by sort_order');
         $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
         $Qimages->bindInt(':sub_products_id', $Qsubproducts->valueInt('products_id'));
         $Qimages->execute();
         $subproducts_array[] = array_merge((array) $Qsubproducts->toArray(), array('image' => $Qimages->value('image')));
         $Qimages->freeResult();
     }
     $data['subproducts'] = $subproducts_array;
     if (sizeof($data['subproducts']) > 0) {
         $data['has_subproducts'] = 1;
     }
     $Qsubproducts->freeResult();
     // load simple options
     $Qoptions = $lC_Database->query('select so.options_id, so.products_id, so.sort_order, so.status, vg.title, vg.module from :table_products_simple_options so left join :table_products_variants_groups vg on (so.options_id = vg.id) where so.products_id = :products_id and vg.languages_id = :languages_id order by so.sort_order');
     $Qoptions->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS);
     $Qoptions->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
     $Qoptions->bindInt(':products_id', $id);
     $Qoptions->bindInt(':languages_id', $lC_Language->getID());
     $Qoptions->execute();
     $cnt = 0;
     while ($Qoptions->next()) {
         $data['simple_options'][$cnt] = $Qoptions->toArray();
         $Qvalues = $lC_Database->query('select sov.products_id, sov.options_id, sov.values_id, sov.price_modifier, sov.customers_group_id, vv.title from :table_products_simple_options_values sov left join :table_products_variants_values vv on (sov.values_id = vv.id) where sov.options_id = :options_id and vv.languages_id = :languages_id order by sov.sort_order');
         $Qvalues->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES);
         $Qvalues->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
         $Qvalues->bindInt(':options_id', $Qoptions->valueInt('options_id'));
         $Qvalues->bindInt(':products_id', $id);
         $Qvalues->bindInt(':languages_id', $lC_Language->getID());
         $Qvalues->execute();
         while ($Qvalues->next()) {
             $data['simple_options'][$cnt]['values'][] = $Qvalues->toArray();
         }
         $Qvalues->freeResult();
         $cnt++;
     }
     $Qoptions->freeResult();
     if (DISPLAY_PRICE_WITH_TAX == 1 || $_SESSION['localization']['show_tax'] == 1) {
         $tax_data = lC_Tax_classes_Admin::getEntry($data['products_tax_class_id']);
         $data['products_price_with_tax'] = $data['products_price'] + $tax_data['tax_rate'] / 100 * $data['products_price'];
         //$data['products_cost_with_tax'] = $data['products_cost'] + ($tax_data['tax_rate']/100)*$data['products_cost'];
         $data['products_msrp_with_tax'] = $data['products_msrp'] + $tax_data['tax_rate'] / 100 * $data['products_msrp'];
     }
     return $data;
 }
 public static function getEntryFormData($id)
 {
     global $lC_Language;
     $lC_Language->loadIniFile('tax_classes.php');
     $lC_Language->loadIniFile('zone_groups.php');
     $result = array();
     $zones_array = array();
     foreach (lC_Zone_groups_Admin::getAllZones() as $group) {
         for ($i = 0; $i < count($group); $i++) {
             $zones_array[$group[$i]['geo_zone_id']] = $group[$i]['geo_zone_name'];
         }
     }
     $result['zonesArray'] = $zones_array;
     if (isset($id) && $id != null) {
         $result['editFormData'] = lC_Tax_classes_Admin::getEntry($id);
     }
     $Qgroups->freeResult;
     return $result;
 }