/** * Checks if file with this name is already exist and generate new name if it is so * * @param string $file path to file * @return string unique file name */ public function generateName($file) { $info = fn_pathinfo($file); while ($this->isExist($file)) { $info['filename'] .= '_' . fn_strtolower(fn_generate_code('', $this->_file_suffix_length)); $file = $info['dirname'] . '/' . $info['filename'] . '.' . $info['extension']; } return $file; }
/** * Checks if file with this name is already exist and generate new name if it is so * * @param string $file path to file * @return string unique file name */ protected function _generateName($file) { if ($this->isExist($file)) { $parts = explode('.', $file); $parts[0] .= '_' . fn_strtolower(fn_generate_code('', $this->_file_suffix_length)); $file = implode('.', $parts); } return $file; }
function fn_generate_gift_certificate_code($quantity = 12) { return fn_generate_code(Registry::get('addons.gift_certificates.code_prefix'), $quantity); }
/** * Apply promotion cart rule * * @param array $promotion promotion array * @param array $cart cart array * @param array $auth (optional) - auth array * @param array $cart_products (optional) - cart products array (for cart rules) * @return bool true if rule can be applied, false - otherwise */ function fn_promotion_apply_cart_rule($bonus, &$cart, &$auth, &$cart_products) { // Clean bonuses if (!isset($cart['promotions'][$bonus['promotion_id']]['bonuses'])) { $cart['promotions'][$bonus['promotion_id']]['bonuses'] = array(); } $bonus_id = count($cart['promotions'][$bonus['promotion_id']]['bonuses']); $cart['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id] = $bonus; if ($bonus['bonus'] == 'order_discount') { if (floatval($cart['subtotal'])) { if (!isset($cart['subtotal_discount'])) { $cart['subtotal_discount'] = 0; } if (fn_allowed_for('MULTIVENDOR')) { $discount = fn_promotions_calculate_order_discount($bonus, $bonus_id, $cart); } else { $discount = fn_promotions_calculate_discount($bonus['discount_bonus'], $cart['subtotal'], $bonus['discount_value']); } if (floatval($discount)) { $cart['use_discount'] = true; $cart['subtotal_discount'] += fn_format_price($discount); } } } elseif ($bonus['bonus'] == 'discount_on_products') { foreach ($cart_products as $k => $v) { if (isset($v['exclude_from_calculate']) || !floatval($v['base_price']) && $v['base_price'] != 0) { continue; } if (fn_promotion_validate_attribute($v['product_id'], $bonus['value'], 'in') && !isset($cart['products'][$k]['extra']['promotions'][$bonus['promotion_id']])) { if (fn_promotion_apply_discount($bonus['promotion_id'], $bonus, $cart_products[$k], true, $cart, $cart_products)) { $cart['use_discount'] = true; } } } } elseif ($bonus['bonus'] == 'discount_on_categories') { foreach ($cart_products as $k => $v) { if (isset($v['exclude_from_calculate']) || !floatval($v['base_price']) && $v['base_price'] != 0) { continue; } if (fn_promotion_validate_attribute($v['category_ids'], $bonus['value'], 'in') && !isset($cart['products'][$k]['extra']['promotions'][$bonus['promotion_id']])) { if (fn_promotion_apply_discount($bonus['promotion_id'], $bonus, $cart_products[$k], true, $cart, $cart_products)) { $cart['use_discount'] = true; } } } } elseif ($bonus['bonus'] == 'give_usergroup') { $cart['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id]['pending'] = true; } elseif ($bonus['bonus'] == 'give_coupon') { $cart['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id]['pending'] = true; $cart['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id]['coupon_code'] = fn_generate_code('', COUPON_CODE_LENGTH); } elseif ($bonus['bonus'] == 'free_shipping') { $cart['free_shipping'][] = $bonus['value']; } elseif ($bonus['bonus'] == 'free_products') { foreach ($bonus['value'] as $p_data) { $product_data = array($p_data['product_id'] => array('amount' => $p_data['amount'], 'product_id' => $p_data['product_id'], 'extra' => array('exclude_from_calculate' => true, 'aoc' => empty($p_data['product_options']), 'saved_options_key' => $bonus['promotion_id'] . '_' . $p_data['product_id']))); if (!empty($cart['saved_product_options'][$bonus['promotion_id'] . '_' . $p_data['product_id']])) { $product_data[$p_data['product_id']]['product_options'] = $cart['saved_product_options'][$bonus['promotion_id'] . '_' . $p_data['product_id']]; } elseif (!empty($p_data['product_options'])) { $product_data[$p_data['product_id']]['product_options'] = $p_data['product_options']; } // Restore object_id if needed if (!empty($cart['saved_object_ids'][$bonus['promotion_id'] . '_' . $p_data['product_id']])) { $product_data[$p_data['product_id']]['saved_object_id'] = $cart['saved_object_ids'][$bonus['promotion_id'] . '_' . $p_data['product_id']]; } $existing_products = array_keys($cart['products']); if (!fn_allowed_for('ULTIMATE') || fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && (fn_check_company_id('products', 'product_id', $p_data['product_id'], Registry::get('runtime.company_id')) || fn_ult_is_shared_product($p_data['product_id'], Registry::get('runtime.company_id')) == 'Y')) { if ($ids = fn_add_product_to_cart($product_data, $cart, $auth)) { $new_products = array_diff(array_keys($cart['products']), $existing_products); if (!empty($new_products)) { $hash = array_pop($new_products); } else { $hash = key($ids); } $_cproduct = fn_get_cart_product_data($hash, $cart['products'][$hash], true, $cart, $auth, !empty($new_products) ? 0 : $p_data['amount']); if (!empty($_cproduct)) { $cart_products[$hash] = $_cproduct; } } } } } return true; }
private static function fn_twg_get_image_by_api_data($api_image) { if (empty($api_image['data']) || empty($api_image['file_name']) && empty($api_image['type'])) { return false; } if (empty($api_image['file_name'])) { $api_image['file_name'] = 'image_' . strtolower(fn_generate_code('', 4)) . '.' . $api_image['type']; } $_data = base64_decode($api_image['data']); $image = array('name' => $api_image['file_name'], 'path' => fn_create_temp_file(), 'size' => strlen($_data)); $file_descriptor = fopen($image['path'], 'wb'); if (!$file_descriptor) { return false; } fwrite($file_descriptor, $_data, $image['size']); fclose($file_descriptor); @chmod($image['path'], DEFAULT_FILE_PERMISSIONS); return $image; }
/** * Generate bonus coupon for order * * @param array $bonus Array with promotion data * @param int $bonus_id Bonus ID * @param array $cart Array with cart data * @return string Coupon code */ function fn_promotion_generate_bonus_coupon($bonus, $bonus_id, $cart) { if (!empty($cart['parent_order_id'])) { $parent_order = fn_promotion_get_order($cart['parent_order_id']); if (!empty($parent_order['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id]['coupon_code'])) { return $parent_order['promotions'][$bonus['promotion_id']]['bonuses'][$bonus_id]['coupon_code']; } } return fn_generate_code('', COUPON_CODE_LENGTH); }