Exemplo n.º 1
0
 public function add($product_id, $quantity = null)
 {
     global $osC_Database, $osC_Services, $osC_Language, $osC_Customer;
     if (!is_numeric($product_id)) {
         return false;
     }
     $Qproduct = $osC_Database->query('select p.parent_id, p.products_price, p.products_tax_class_id, p.products_model, p.products_weight, p.products_weight_class, p.products_status, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id');
     $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
     $Qproduct->bindInt(':default_flag', 1);
     $Qproduct->bindInt(':products_id', $product_id);
     $Qproduct->execute();
     if ($Qproduct->valueInt('products_status') === 1) {
         if ($this->exists($product_id)) {
             $item_id = $this->getBasketID($product_id);
             if (!is_numeric($quantity)) {
                 $quantity = $this->getQuantity($item_id) + 1;
             }
             $this->_contents[$item_id]['quantity'] = $quantity;
             if ($osC_Customer->isLoggedOn()) {
                 $Qupdate = $osC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
                 $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qupdate->bindInt(':quantity', $quantity);
                 $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
                 $Qupdate->bindInt(':item_id', $item_id);
                 $Qupdate->execute();
             }
         } else {
             if (!is_numeric($quantity)) {
                 $quantity = 1;
             }
             $Qdescription = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
             $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qdescription->bindInt(':products_id', $Qproduct->valueInt('parent_id') > 0 ? $Qproduct->valueInt('parent_id') : $product_id);
             $Qdescription->bindInt(':language_id', $osC_Language->getID());
             $Qdescription->execute();
             $price = $Qproduct->value('products_price');
             if ($osC_Services->isStarted('specials')) {
                 global $osC_Specials;
                 if ($new_price = $osC_Specials->getPrice($product_id)) {
                     $price = $new_price;
                 }
             }
             if ($osC_Customer->isLoggedOn()) {
                 $Qid = $osC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id');
                 $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qid->bindInt(':customers_id', $osC_Customer->getID());
                 $Qid->execute();
                 $item_id = $Qid->valueInt('item_id') + 1;
             } else {
                 if (empty($this->_contents)) {
                     $item_id = 1;
                 } else {
                     $item_id = max(array_keys($this->_contents)) + 1;
                 }
             }
             $this->_contents[$item_id] = array('item_id' => $item_id, 'id' => $product_id, 'parent_id' => $Qproduct->valueInt('parent_id'), 'name' => $Qdescription->value('products_name'), 'model' => $Qproduct->value('products_model'), 'keyword' => $Qdescription->value('products_keyword'), 'image' => $Qproduct->value('image'), 'price' => $price, 'quantity' => $quantity, 'weight' => $Qproduct->value('products_weight'), 'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'), 'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()), 'weight_class_id' => $Qproduct->valueInt('products_weight_class'));
             if ($osC_Customer->isLoggedOn()) {
                 $Qnew = $osC_Database->query('insert into :table_shopping_carts (customers_id, item_id, products_id, quantity, date_added) values (:customers_id, :item_id, :products_id, :quantity, :date_added)');
                 $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qnew->bindInt(':customers_id', $osC_Customer->getID());
                 $Qnew->bindInt(':item_id', $item_id);
                 $Qnew->bindInt(':products_id', $product_id);
                 $Qnew->bindInt(':quantity', $quantity);
                 $Qnew->bindRaw(':date_added', 'now()');
                 $Qnew->execute();
             }
             if ($Qproduct->valueInt('parent_id') > 0) {
                 $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvg.module, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg 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');
                 $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                 $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                 $Qvariant->bindInt(':products_id', $product_id);
                 $Qvariant->bindInt(':languages_id', $osC_Language->getID());
                 $Qvariant->bindInt(':languages_id', $osC_Language->getID());
                 $Qvariant->execute();
                 while ($Qvariant->next()) {
                     $group_title = osC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray());
                     $value_title = osC_Variants::getValueTitle($Qvariant->value('module'), $Qvariant->toArray());
                     $has_custom_value = osC_Variants::hasCustomValue($Qvariant->value('module'));
                     $this->_contents[$item_id]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'), 'value_id' => $Qvariant->valueInt('value_id'), 'group_title' => $group_title, 'value_title' => $value_title, 'has_custom_value' => $has_custom_value);
                     if ($osC_Customer->isLoggedOn() && $has_custom_value === true) {
                         $Qnew = $osC_Database->query('insert into :table_shopping_carts_custom_variants_values (shopping_carts_item_id, customers_id, products_id, products_variants_values_id, products_variants_values_text) values (:shopping_carts_item_id, :customers_id, :products_id, :products_variants_values_id, :products_variants_values_text)');
                         $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
                         $Qnew->bindInt(':shopping_carts_item_id', $item_id);
                         $Qnew->bindInt(':customers_id', $osC_Customer->getID());
                         $Qnew->bindInt(':products_id', $product_id);
                         $Qnew->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id'));
                         $Qnew->bindValue(':products_variants_values_text', $value_title);
                         $Qnew->execute();
                     }
                 }
             }
         }
         $this->_cleanUp();
         $this->_calculate();
     }
 }
Exemplo n.º 2
0
      <tr>
        <td colspan="3" align="right"><input type="button" value="Add Variant" class="infoBoxButton" onclick="addVariant();" /></td>
      </tr>
      <tr>
        <td width="30%" valign="top">
          <select name="variantGroups" ondblclick="moreFields();" size="20" style="width: 100%;">

<?php 
$Qvgroups = $osC_Database->query('select id, title, module from :table_products_variants_groups where languages_id = :languages_id order by sort_order, title');
$Qvgroups->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
$Qvgroups->bindInt(':languages_id', $osC_Language->getID());
$Qvgroups->execute();
$has_multiple_value_groups = false;
while ($Qvgroups->next()) {
    $vgroup_title = $Qvgroups->value('title');
    if (osC_Variants::allowsMultipleValues($Qvgroups->value('module'))) {
        if ($has_multiple_value_groups === false) {
            $has_multiple_value_groups = true;
        }
        $vgroup_title .= ' (*)';
    }
    echo '          <optgroup label="' . $vgroup_title . '" id="' . $Qvgroups->valueInt('id') . '">' . "\n";
    $Qvvalues = $osC_Database->query('select id, title from :table_products_variants_values where products_variants_groups_id = :products_variants_groups_id and languages_id = :languages_id order by sort_order, title');
    $Qvvalues->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
    $Qvvalues->bindInt(':products_variants_groups_id', $Qvgroups->valueInt('id'));
    $Qvvalues->bindInt(':languages_id', $osC_Language->getID());
    $Qvvalues->execute();
    while ($Qvvalues->next()) {
        echo '            <option value="' . $Qvvalues->valueInt('id') . '">' . $Qvvalues->value('title') . '</option>' . "\n";
    }
    echo '          </optgroup>' . "\n";
Exemplo n.º 3
0
if ($osC_Product->hasVariants()) {
    ?>

    <div id="variantsBlock">
      <div id="variantsBlockTitle"><?php 
    echo $osC_Language->get('product_attributes');
    ?>
</div>

      <div id="variantsBlockData">

<?php 
    foreach ($osC_Product->getVariants() as $group_id => $value) {
        echo osC_Variants::parse($value['module'], $value);
    }
    echo osC_Variants::defineJavascript($osC_Product->getVariants(false));
    ?>

      </div>
    </div>

<?php 
}
?>

    </form>
  </div>
</div>

<div style="clear: both;"></div>
Exemplo n.º 4
0
 public static function defineJavascript($products)
 {
     global $osC_Currencies;
     $string = '<script language="javascript" type="text/javascript">var combos = new Array();' . "\n";
     foreach ($products as $product_id => $product) {
         $string .= 'combos[' . $product_id . '] = new Array();' . "\n" . 'combos[' . $product_id . '] = { price: "' . addslashes($osC_Currencies->displayPrice($product['data']['price'], $product['data']['tax_class_id'])) . '", model: "' . addslashes($product['data']['model']) . '", availability_shipping: ' . (int) $product['data']['availability_shipping'] . ', values: [] };' . "\n";
         foreach ($product['values'] as $group_id => $variants) {
             $check_flag = false;
             foreach ($variants as $variant) {
                 if (!osC_Variants::hasCustomValue($variant['module'])) {
                     if ($check_flag === false) {
                         $check_flag = true;
                         $string .= 'combos[' . $product_id . ']["values"][' . $group_id . '] = new Array();' . "\n";
                     }
                     $string .= 'combos[' . $product_id . ']["values"][' . $group_id . '][' . $variant['value_id'] . '] = ' . $variant['value_id'] . ';' . "\n";
                 }
             }
         }
     }
     $string .= '</script>';
     return $string;
 }