public function AddPhotoProduct($data) { // try to create new product if (!($id_product = $this->AddProduct($data))) { return false; } $article = $this->GetArtByID($id_product); // try to add photos to the new product foreach ($data['images'] as $k => $image) { $to_resize[] = $newname = $article['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $file = pathinfo($image['src']); $path = $GLOBALS['PATH_root'] . $file['dirname'] . '/'; $bd_path = $file['dirname']; rename($path . $file['basename'], $path . $newname); $images_arr[] = $file['dirname'] . '/' . $newname; $visibility[] = $image['visible'] == 'true' ? 1 : 0; } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер foreach ($images_arr as $filename) { $size = getimagesize($GLOBALS['PATH_root'] . $filename); //Получаем ширину, высоту, тип картинки 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; } } else { $width = $size[0]; $height = $size[1]; } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($GLOBALS['PATH_root'] . $filename) : imagecreatefrompng($GLOBALS['PATH_root'] . $filename); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); imagejpeg($res, $GLOBALS['PATH_root'] . $filename); } $Images = new Images(); $Images->resize(false, $to_resize); $this->UpdatePhoto($id_product, $images_arr, $visibility); // try to add videos if (!empty($_POST['video'])) { $this->UpdateVideo($id_product, $_POST['video']); } // try to add new product to supplier's assort $Suppliers = new Suppliers(); $id_supplier = $Suppliers->GetSupplierIdByArt($data['art_supplier']); if (!$this->AddToAssort($id_product, $id_supplier)) { return false; } // Добавление данных в таблицу photo_batch $date = date('Y-m-d'); $id_author = $_SESSION['member']['id_user']; $id_batch = $this->GetIdPhotoBatch($date, $id_supplier, $id_author); if ($id_batch) { $this->AddPhotoBatchProducts($id_batch, $id_product); } else { $f['date'] = date('Y-m-d'); $f['id_supplier'] = $id_supplier; $f['id_author'] = $id_author; $this->db->StartTrans(); if (!$this->db->Insert(_DB_PREFIX_ . 'photo_batch', $f)) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); $id_batch = $this->GetIdPhotoBatch($date, $id_supplier, $id_author); $this->AddPhotoBatchProducts($id_batch, $id_product); } return $id_product; }
public function ExecuteContragentOrder($arr, $id_order) { $Supplier = new Suppliers(); $sql = "SELECT id_product, site_price_opt, site_price_mopt\r\n\t\t\tFROM " . _DB_PREFIX_ . "osp\r\n\t\t\tWHERE id_order = " . $id_order; $prices = $this->db->GetArray($sql, "id_product"); if (isset($arr['contr_qty'])) { foreach ($arr['contr_qty'] as $id_product => $contr_qty) { $sql = "UPDATE " . _DB_PREFIX_ . "osp\r\n\t\t\t\t\tSET contragent_qty = " . $contr_qty . ",\r\n\t\t\t\t\t\tcontragent_sum = " . round($arr['contr_qty'][$id_product] * $prices[$id_product]['site_price_opt'], 2) . ",\r\n\t\t\t\t\t\tid_supplier = {$Supplier->GetSupplierIdByArt($arr['article'][$id_product])}\r\n\t\t\t\t\tWHERE id_order = " . $id_order . "\r\n\t\t\t\t\tAND id_product = " . $id_product; $this->db->StartTrans(); if (!$this->db->Query($sql)) { $this->db->FailTrans(); G::DieLoger("SQL error - {$sql}"); return false; } $this->db->CompleteTrans(); } } if (isset($arr['contr_mqty'])) { foreach ($arr['contr_mqty'] as $id_product => $contr_mqty) { $sql = "UPDATE " . _DB_PREFIX_ . "osp\r\n\t\t\t\t\tSET contragent_mqty = " . $contr_mqty . ",\r\n\t\t\t\t\t\tcontragent_msum = " . round($arr['contr_mqty'][$id_product] * $prices[$id_product]['site_price_mopt'], 2) . ",\r\n\t\t\t\t\t\tid_supplier_mopt = {$Supplier->GetSupplierIdByArt($arr['article_mopt'][$id_product])}\r\n\t\t\t\t\tWHERE id_order = " . $id_order . "\r\n\t\t\t\t\tAND id_product = " . $id_product; $this->db->StartTrans(); if (!$this->db->Query($sql)) { $this->db->FailTrans(); G::DieLoger("SQL error - {$sql}"); return false; } $this->db->CompleteTrans(); } } $sql = "UPDATE " . _DB_PREFIX_ . "order\r\n\t\t\tSET id_order_status = 2\r\n\t\t\tWHERE id_order = " . $id_order; $this->db->StartTrans(); if (!$this->db->Query($sql)) { $this->db->FailTrans(); G::DieLoger("SQL error - {$sql}"); return false; } $this->db->CompleteTrans(); return true; }
break; case 'removeSupplierAssort': if (!$Products->deleteSupplierAssort($_POST['id_assort'])) { return false; } return true; break; case 'updateActiveAssort': if (!$Products->updateActiveAssort($_POST['id_assort'], $_POST['active'])) { return false; } return true; break; case 'addSupplier': $Suppliers = new Suppliers(); $id_supplier = $Suppliers->GetSupplierIdByArt($_POST['article']); $Suppliers->SetFieldsByID($id_supplier); $_POST['product_limit'] = $_POST['active'] == 1 ? 10000000 : 0; if ($_POST['price_opt_otpusk'] == 0 && $_POST['price_mopt_otpusk'] == 0) { $_POST['product_limit'] = 0; $_POST['active'] = 0; } if ($_POST['inusd'] == 1) { $_POST['price_mopt_otpusk_usd'] = $_POST['price_mopt_otpusk']; $_POST['price_mopt_otpusk'] = $_POST['price_mopt_otpusk'] * $Suppliers->fields['currency_rate']; $_POST['price_opt_otpusk_usd'] = $_POST['price_opt_otpusk']; $_POST['price_opt_otpusk'] = $_POST['price_opt_otpusk'] * $Suppliers->fields['currency_rate']; } else { $_POST['price_mopt_otpusk_usd'] = $_POST['price_mopt_otpusk'] / $Suppliers->fields['currency_rate']; $_POST['price_opt_otpusk_usd'] = $_POST['price_opt_otpusk'] / $Suppliers->fields['currency_rate']; }