<?if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ header('Content-Type: text/javascript; charset=utf-8'); $Products = new Products(); if(isset($_POST['action'])) switch($_POST['action']){ case 'specification_update': $Specification = new Specification(); $Products->UpdateProduct(array('id_product'=>$_POST['id_product'])); if($_POST['id_spec_prod'] == ''){ if($Specification->AddSpecToProd($_POST, $_POST['id_product'])){ echo json_encode('ok'); } }else{ if($Specification->UpdateSpecsInProducts($_POST)){ echo json_encode('ok'); } } break; case 'update_translit': echo json_encode($Products->UpdateTranslit($_POST['id_product'])); break; case 'datalist': echo json_encode($Products->GetIdOneRowArrayByArt($_POST['article'])); break; case 'datalist_supplier': $Supplier = new Suppliers(); echo json_encode($Supplier->GetIdOneRowArrayByArt($_POST['article'])); break; case 'insert_related': echo json_encode($Products->AddRelatedProduct($_POST['id_prod'], $_POST['id_related_prod'])); break;
public function parseUrl($url) { $Products = new Products(); $Specification = new Specification(); $Images = new Images(); $product = array(); $html = file_get_html($url); if (!$html) { return false; } // Название товара $product['name'] = $html->find('[itemprop="name"]', 0)->plaintext; if (!$product['name']) { return false; } // if($Products->SetFieldsByRewrite(G::StrToTrans($product['name']))){ // return false; // } // Описание товара $product['descr'] = $html->find('[itemprop="description"]', 0)->plaintext; // Указываем базовую активность товара $product['active'] = 1; // Получаем цену товара $product['price_opt_otpusk'] = $product['price_mopt_otpusk'] = $html->find('[itemprop="price"]', 0)->innertext; // Находим характеристики товара foreach ($html->find('.stats tr') as $element) { $caption = trim($element->find('.name span', 0)->innertext); if ($caption == 'Артикул') { $sup_comment = trim($element->children(1)->plaintext); } elseif ($caption !== '' && !in_array($caption, array('Доставка', 'Самовывоз', 'Гарантия'))) { $value = trim($element->children(1)->plaintext); $spec = $Specification->SpecExistsByCaption($caption); $product['specs'][] = array('id_spec' => $spec ? $spec['id'] : $Specification->Add(array('caption' => $caption)), 'value' => $value); } } // Выбираем изображения максимального размера foreach ($html->find('#photo #elementTableImg img') as $element) { $filename = 'http://zona220.com' . str_replace('/500_500_1/', '/', str_replace('/resize_cache/', '/', $element->src)); $img_info = array_merge(getimagesize($filename), pathinfo($filename)); $path = $GLOBALS['PATH_product_img'] . 'original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $Images->checkStructure($path); copy($filename, $path . $img_info['basename']); $product['images'][] = str_replace($GLOBALS['PATH_global_root'], '/', $path . $img_info['basename']); $product['images_visible'][] = 1; } $html->clear(); unset($html); // Добавляем новый товар в БД if ($id_product = $Products->AddProduct($product)) { // Добавляем характеристики новому товару if (!empty($product['specs'])) { foreach ($product['specs'] as $specification) { $Specification->AddSpecToProd($specification, $id_product); } } // Формирем массив записи ассортимента $assort = array('id_assortiment' => false, 'id_supplier' => 25392, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0, 'sup_comment' => $sup_comment); // $assort = array('id_assortiment' => false, 'id_supplier' => 23029, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0); // Добавляем зпись в ассортимент $Products->AddToAssortWithAdm($assort); // Получаем артикул нового товара $article = $Products->GetArtByID($id_product); // Переименовываем фото товара $to_resize = $images_arr = array(); if (isset($product['images'])) { foreach ($product['images'] as $k => $image) { $to_resize[] = $newname = $article['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $file = pathinfo(str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $image)); $path = $GLOBALS['PATH_product_img'] . trim($file['dirname']) . '/'; $images_arr[] = str_replace($file['basename'], $newname, $image); rename($path . $file['basename'], $path . $newname); } } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер foreach ($images_arr as $filename) { $file = $GLOBALS['PATH_product_img'] . str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $filename); $size = getimagesize($file); // $size = getimagesize($path.$filename); //Получаем ширину, высоту, тип картинки $width = $size[0]; $height = $size[1]; if ($size[0] > 1000 || $size[1] > 1000) { $ratio = $size[0] / $size[1]; //коэфициент соотношения сторон //Определяем размеры нового изображения if (max($size[0], $size[1]) == $size[0]) { $width = 1000; $height = 1000 / $ratio; } elseif (max($size[0], $size[1]) == $size[1]) { $width = 1000 * $ratio; $height = 1000; } } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($file) : imagecreatefrompng($file); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); $stamp = imagecreatefrompng($GLOBALS['PATH_global_root'] . 'images/watermark.png'); imagecopyresampled($res, $stamp, 10, 10, 0, 0, imagesx($stamp), imagesy($stamp), imagesx($stamp), imagesy($stamp)); imagejpeg($res, $file); } $Images->resize(false, $to_resize); // Привязываем новые фото к товару в БД $Products->UpdatePhoto($id_product, $images_arr, $product['images_visible']); } return $id_product; }
/** * [DuplicateProduct description] * @param [type] $data [description] */ public function DuplicateProduct($data) { // creating new article $art = $this->CheckArticle((int) $this->GetLastArticle()); // duplicating main product information & category $this->SetFieldsById($data['id_product']); $old_product_info = $this->fields; $old_product_info['art'] = $art; // $old_product_info['dupl_idproduct'] = $data['id_product']; $old_product_info['name'] .= ' ' . $art; if (!($id_product = $this->AddProduct($old_product_info))) { return false; } // duplicating product assortment $sql = "SELECT * FROM " . _DB_PREFIX_ . "assortiment AS a\n\t\t\tWHERE a.id_product = " . $data['id_product']; $res = $this->db->GetArray($sql); if (!empty($res)) { foreach ($res as &$value) { $value['id_product'] = $id_product; $this->AddToAssortWithAdm($value); } } // duplicating product specifications $sql = "SELECT * FROM " . _DB_PREFIX_ . "specs_prods as s\n\t\t\tWHERE s.id_prod = " . $data['id_product']; $res = $this->db->GetArray($sql); if (!empty($res)) { $specifications = new Specification(); foreach ($res as $value) { $specifications->AddSpecToProd($value, $id_product); } } // duplicating product segmentation $sql = "SElECT * FROM " . _DB_PREFIX_ . "segment_prods AS sp\n\t\tWHERE sp.id_product = " . $data['id_product']; $res = $this->db->GetArray($sql); if (!empty($res)) { $segmentation = new Segmentation(); foreach ($res as $value) { $segmentation->AddSegmentInProduct($id_product, $value['id_segment']); } } // duplicating product videos $res = $this->GetVideoById($data['id_product']); if (!empty($res)) { $this->UpdateVideo($id_product, $res); } // duplicating product images $res = $this->GetPhotoById($data['id_product']); foreach ($res as &$value) { $value = $value['src']; } if (!empty($res)) { $this->UpdatePhoto($id_product, $res); } return $id_product; }
$tpl->Assign('pops1', $pops1); $tpl->Assign('related_prods_list', $Products->GetArrayRelatedProducts($id_product)); $specification->SetListByProdId($id_product); $tpl->Assign('product_specs', $specification->list); $specification->SetList(); $tpl->Assign('specs', $specification->list); $tpl->Assign('unitslist', $Unit->GetUnitsList()); $tpl->Assign('list_segment_types', $segmentation->GetSegmentationType()); if (isset($_GET['upload']) == true) { $res = $Images->upload($_FILES, $GLOBALS['PATH_product_img'] . 'original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'); echo str_replace($GLOBALS['PATH_root'], '/', $res); exit(0); } if (isset($_GET['action']) && $_GET['action'] == "update_spec") { if ($_GET['id_spec_prod'] == '') { $specification->AddSpecToProd($_GET, $id_product); } else { $specification->UpdateSpecsInProducts($_GET); } header('Location: ' . $GLOBALS['URL_base'] . 'adm/productedit/' . $id_product); } elseif (isset($_GET['action']) && $_GET['action'] == "delete_spec") { $specification->DelSpecFromProd($_GET['id_spec_prod']); $Products->UpdateProduct(array('id_product' => $id_product)); header('Location: ' . $GLOBALS['URL_base'] . 'adm/productedit/' . $id_product); } if (isset($_POST['smb']) || isset($_POST['smb_new'])) { require_once $GLOBALS['PATH_block'] . 't_fnc.php'; // для ф-ции проверки формы if (isset($_POST['price']) && $_POST['price'] == "") { $_POST['price'] = 0; }