/** * Clone accessories when product cloned * POST hook * @see include/func/cw.product.php: cw_product_clone() * */ function cw_ac_product_clone($product_id) { $new_product_id = cw_get_return(); if (!empty($new_product_id)) { cw_core_copy_tables('linked_products', 'product_id', $product_id, $new_product_id); } return $new_product_id; }
/** * what function does * * @see POST hook for cw_original_hooked_function * ... */ function cw_original_hooked_function($param1, $param2) { $return = cw_get_return(); // Get return of previous hook // Do something usgin $return return $return; // Do not forget return same value }
/** * Clone tabs when product cloned * POST hook * @see include/func/cw.product.php: cw_product_clone() * */ function cw_pt_product_clone($product_id) { global $_pt_addon_tables; $new_product_id = cw_get_return(); if (!empty($new_product_id)) { cw_core_copy_tables($_pt_addon_tables['product'], 'product_id', $product_id, $new_product_id); } return $new_product_id; }
function cw_error_check(&$array_to_check, $rules, $attributes_type = '') { $result = cw_get_return(); // get array of errors returned by core cw_error_check() if ($attributes_type != 'P' || is_null($result)) { return $result; } // hook for products only if (!cw_is_catalog_product($array_to_check)) { return $result; } // do not check other product types if (empty($array_to_check['attributes']['original_url'])) { cw_add_top_message(cw_get_langvar_by_name('err_field_catalog_products', '', false, true), 'W'); } return $result; }
function cw_flexible_import_validate_import_file($params, $rules) { $error = cw_get_return(); global $action; if ($action != "import_file") { return $error; } $index = substr_count($error, "\n") + ($error != '' ? 1 : 0); if (isset($params['import_file']['error']) && $params['import_file']['error'] != 0 && $params['import_type'] == 'pc') { if ($params['import_file']['error'] == 4) { $error .= "\n" . ++$index . 'b . ' . cw_get_langvar_by_name('err_field_select_file'); } else { $error .= "\n" . ++$index . '. ' . cw_get_langvar_by_name('lbl_upld_err') . ' ' . $params['import_file']['error']; } } elseif (empty($params['import_file'])) { $error .= "\n" . ++$index . 'c . ' . cw_get_langvar_by_name('err_field_select_file'); } $error = str_replace('<br/>', '', $error); return $error; }
function cw_ps_aom_recalculate_totals_extra($order) { $cart = cw_get_return(); $extra = cw_call('cw_ps_on_place_order_extra', array(array())); $cart['info']['extra'] = array_merge($cart['info']['extra'], $extra); return $cart; }
function cw_core_get_meta($tag) { global $smarty, $location, $config; if ($ret = cw_get_return()) { return $ret; } if ($tag == 'title') { // if ($config['SEO']['page_title_format'] == 'D') $location = array_reverse($location); $tmp = array(); if ($location) { // foreach($location as $v) $tmp[] = $v[0]; $tmp[] = $location[0][0]; $last_title_part = cw_call('cw_core_get_last_title_part', array($location)); if (!empty($last_title_part)) { $tmp[] = $last_title_part; } // if (($cnt=count($location))>1) // $tmp[] = $location[$cnt-1][0]; } if ($config['SEO']['page_title_format'] == 'D') { $tmp = array_reverse($tmp); } $ret = strip_tags(implode(' | ', $tmp)); } elseif ($tag == 'keywords') { $ret = cw_get_langvar_by_name('lbl_site_meta_keywords'); } elseif ($tag == 'description') { if ($smarty->_tpl_vars['product']) { $ret = $smarty->_tpl_vars['product']['descr']; } elseif ($smarty->_tpl_vars['manufacturer']) { $ret = $smarty->_tpl_vars['manufacturer']['descr']; } elseif ($smarty->_tpl_vars['page_data']) { $ret = $smarty->_tpl_vars['page_data']['content']; } elseif ($smarty->_tpl_vars['current_category']) { $ret = $smarty->_tpl_vars['current_category']['description']; } $ret = substr(strip_tags($ret . cw_get_langvar_by_name('lbl_site_meta_descr')), 0, 255); } return $ret; }
function cw_review_doc_get($doc_id, $info_type = 0) { global $tables, $current_location; $return = cw_get_return(); if (!empty($return) && $return['type'] == 'O' && (!empty($return['products']) || !empty($return['giftcerts'])) && !empty($return['userinfo']['customer_id'])) { if (!empty($return['giftcerts']) && is_array($return['giftcerts'])) { foreach ($return['giftcerts'] as $key => $giftcert) { $return['giftcerts'][$key]['review_note'] = ''; } } if (!empty($return['products']) && is_array($return['products'])) { foreach ($return['products'] as $key => $product) { $product_id = $product['product_id']; $customer_id = $return['userinfo']['customer_id']; $result = cw_query_first_cell("\n SELECT review_id\n FROM {$tables['products_reviews']}\n WHERE product_id='{$product_id}' AND customer_id='{$customer_id}'\n "); $review_note = ''; if (!$result) { $review_note = "<a href='{$current_location}/index.php?target=product&product_id={$product_id}' target='_blank'>Place review</a>"; } $return['products'][$key]['review_note'] = $review_note; } } return new EventReturn($return); } return $return; }
function cw_ps_on_place_order_extra($params) { global $cart; $special_offers_apply =& cw_session_register("special_offers_apply"); $extra = cw_get_return(); if (!empty($special_offers_apply)) { $extra['promotion_suite'] = $special_offers_apply; } if (!empty($cart['info']['shipping_no_offer'])) { $extra['shipping_no_offer'] = $cart['info']['shipping_no_offer']; } return $extra; }
function cw_manufacturers_doc_get_extras_data($doc_id) { global $tables; $return = cw_get_return(); $attribute_id = cw_call('cw_attributes_get_attribute_by_field', array('field' => 'manufacturer_id')); $return['manufacturers'] = cw_query_first_cell("SELECT GROUP_CONCAT(manufacturer) as manufacturers\n FROM {$tables['manufacturers']}\n INNER JOIN {$tables['attributes_values']} on {$tables['attributes_values']}.value = {$tables['manufacturers']}.manufacturer_id\n INNER JOIN {$tables['docs_items']} on {$tables['docs_items']}.product_id = {$tables['attributes_values']}.item_id\n WHERE cw_docs_items.doc_id = '" . $doc_id . "'\n AND cw_attributes_values.attribute_id = " . $attribute_id); $return['manufacturers'] = str_replace(',', ', ', $return['manufacturers']); return $return; }
/** * get mail lists * * @return array|null */ function cw_vertical_response_get_newslists() { global $config; $return = cw_get_return(); $vertical_response_data = cw_session_register('vertical_response_data'); if (isset($vertical_response_data['lists']) && !empty($vertical_response_data['lists'])) { foreach ($vertical_response_data['lists'] as $list) { if ($list->status == 'active') { $return[] = array('id' => $list->id, 'list_id' => 'vr_' . $list->id, 'name' => $list->name, 'descr' => $list->name); } } } else { $vertical_response_email = trim($config[vertical_response_addon_name]['vertical_response_email']); $vertical_response_password = trim($config[vertical_response_addon_name]['vertical_response_password']); try { $vr = new SoapClient(vertical_response_wsdl, array('connection_timeout' => 5)); $sid = $vr->login(array('username' => "{$vertical_response_email}", 'password' => "{$vertical_response_password}", 'session_duration_minutes' => vertical_response_ses_time)); // get all lists $lists = $vr->enumerateLists(array('session_id' => $sid, 'type' => 'email', 'include_field_info' => false, 'limit' => 20)); if (!empty($lists) && count($lists)) { foreach ($lists as $list) { if ($list->status == 'active') { $return[] = array('id' => $list->id, 'list_id' => 'vr_' . $list->id, 'name' => $list->name, 'descr' => $list->name); } } } } catch (SoapFault $exception) { //exit ('fault: "' . $exception->faultcode . '" - ' . $exception->faultstring . "\n"); } } return $return; }
function cw_product_options_clone($product_id) { global $tables, $addons, $config; $new_product_id = cw_get_return(); cw_core_copy_tables('product_options_js', 'product_id', $product_id, $new_product_id); $hash = array(); $classes = cw_query("SELECT * FROM {$tables['product_options']} WHERE product_id = '{$product_id}'"); if (!empty($classes)) { foreach ($classes as $v) { $options = cw_query("SELECT * FROM {$tables['product_options_values']} WHERE product_option_id = '{$v['product_option_id']}'"); $old_classid = $v['product_option_id']; unset($v['product_option_id']); $v['product_id'] = $new_product_id; $v = cw_addslashes($v); $classid = cw_array2insert('product_options', $v); if ($options) { foreach ($options as $o) { $old_optionid = $o['option_id']; unset($o['option_id']); $o['product_option_id'] = $classid; $o = cw_addslashes($o); $optionid = cw_array2insert('product_options_values', $o); $hash[$old_optionid] = $optionid; cw_core_copy_tables('product_options_values_lng', 'option_id', $old_optionid, $optionid); } } cw_core_copy_tables('product_options_lng', 'product_option_id', $old_classid, $classid); } } // Clone product option exceptions if (!empty($hash)) { $hash_ex = array(); $exceptions = cw_query("SELECT * FROM {$tables['products_options_ex']} WHERE option_id IN ('" . implode("','", array_keys($hash)) . "')"); if (!empty($exceptions)) { foreach ($exceptions as $v) { if (empty($hash[$v['option_id']])) { continue; } $v['option_id'] = $hash[$v['option_id']]; if (empty($hash_ex[$v['exception_id']])) { $hash_ex[$v['exception_id']] = cw_query_first_cell("SELECT MAX(exception_id) FROM {$tables['product_options_ex']}") + 1; } $v['exception_id'] = $hash_ex[$v['exception_id']]; cw_array2insert('products_options_ex', $v); } } unset($hash_ex); } // Clone product option variants $variants = db_query("SELECT * FROM {$tables['product_variants']} WHERE product_id = '{$product_id}' ORDER BY variant_id"); if ($variants) { while ($v = db_fetch_array($variants)) { $old_variantid = $v['variant_id']; $v['product_id'] = $new_product_id; unset($v['variant_id']); $v['productcode'] = cw_product_generate_sku(); if ($addons['barcode'] && $config['barcode']['gen_product_code']) { $v['eancode'] = cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'); } else { $v['eancode'] = cw_product_generate_sku(0, 'eancode'); } //cw_ean_clear($v['eancode']); $v = cw_addslashes($v); $variantid = cw_array2insert('product_variants', $v); // Add Variant items $items = cw_query("SELECT option_id FROM {$tables['product_variant_items']} WHERE variant_id = '{$old_variantid}'"); if (!empty($items)) { foreach ($items as $i) { if (isset($hash[$i['option_id']])) { db_query("INSERT INTO {$tables['product_variant_items']} (variant_id, option_id) VALUES ('{$variantid}', '" . $hash[$i['option_id']] . "')"); } } } // warehouse if ($addons['warehouse']) { $items = cw_query("SELECT * FROM {$tables['products_warehouses_amount']} WHERE variant_id = '{$old_variantid}' AND product_id = '{$product_id}'"); if (!empty($items)) { foreach ($items as $i) { db_query("INSERT INTO {$tables['products_warehouses_amount']} (product_id, warehouse_customer_id, avail, avail_ordered, avail_sold, avail_reserved, variant_id) VALUES ('{$new_product_id}', '" . $i['warehouse_customer_id'] . "', '" . $i['avail'] . "', '" . $i['avail_ordered'] . "', '" . $i['avail_sold'] . "', '" . $i['avail_reserved'] . "', '{$variantid}')"); } } } // Add Variant prices $prices = cw_query("SELECT * FROM {$tables['products_prices']} WHERE variant_id = '{$old_variantid}' AND product_id = '{$product_id}'"); if ($prices) { foreach ($prices as $p) { unset($p['price_id']); $p['variant_id'] = $variantid; $p['product_id'] = $new_product_id; cw_array2insert('products_prices', $p); } } // Add Variant thumbnails & variant images cw_core_copy_tables('products_images_var', 'id', $old_variantid, $variantid); } db_free_result($variants); } return $new_product_id; }
function cw_md_core_get_config() { global $tables, $current_domain; $return = cw_get_return(); if (APP_AREA != 'customer') { return $return; } if ($config_tmp = db_query("select name, value, category from {$tables['domains_config']} as dc, {$tables['config_categories']} as cc where cc.config_category_id = dc.config_category_id and dc.domain_id = '{$current_domain}'")) { while ($arr = db_fetch_array($config_tmp)) { if ($arr['category'] == 'main') { if (isset($return[$arr['name']])) { $return[$arr['name']] = $arr['value']; } } elseif ($arr['type'] == 'multiselector') { if (isset($return[$arr['category']][$arr['name']])) { $return[$arr['category']][$arr['name']] = explode(';', $arr['value']); } } else { if (isset($return[$arr['category']][$arr['name']])) { $return[$arr['category']][$arr['name']] = $arr['value']; } } } db_free_result($config_tmp); } return $return; }
function cw_attributes_get_attribute_by_field($field) { global $tables; if ($ret = cw_get_return()) { return $ret; } // pre-hook can override this function for certain field by returning own value if (!is_array($field)) { $fields = array($field); } else { $fields = $field; } $ret = array(); foreach ($fields as $f) { $att = cw_call('cw_attributes_filter', array(array('field' => $f), true)); if ($att) { $ret[$att['field']] = $att['attribute_id']; } } if (!is_array($field)) { return array_pop($ret); } return $ret; }
function cw_product_shipping_option_get_layout($layout) { $return = cw_get_return(); if (!empty($return) && $return['layout'] == 'docs_O' && !empty($return['data']) && !empty($return['data']['elements'])) { $elems = array(); foreach ($return['data']['elements'] as $key => $val) { $elems[] = $val; if ($val == 'amount') { $elems[] = 'product_shipping_option'; } } $return['data']['elements'] = $elems; return new EventReturn($return); } return $return; }
function cw_clean_url_category_delete($cat, $is_show_process = false) { global $tables, $config; $return = cw_get_return(); $orphaned_cats = cw_query_column("SELECT u.item_id FROM {$tables['clean_urls_history']} u \n\tLEFT JOIN {$tables['categories']} c ON c.category_id=u.item_id WHERE u.item_type='C' AND c.category_id IS NULL"); if ($cat != 0) { $orphaned_cats[] = $cat; } if (!empty($subcats) && is_array($subcats)) { db_exec("DELETE FROM {$tables['clean_urls_history']} WHERE item_type = 'C' AND item_id IN (?)", array($orphaned_cats)); } return $return; }