本文整理汇总了PHP中Product::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::update方法的具体用法?PHP Product::update怎么用?PHP Product::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_update
public function test_update()
{
/** === Test Data === */
$MAGE_ID = 1234;
$NAME = 'product name';
$IS_ACTIVE = true;
$PRICE = 43.21;
$WEIGHT = 54.321;
/** === Setup Mocks === */
// $product = $this->_mageRepoProd->getById($mageId);
$mProduct = $this->_mock(\Magento\Catalog\Api\Data\ProductInterface::class);
$this->mMageRepoProd->shouldReceive('getById')->once()->andReturn($mProduct);
$mProduct->shouldReceive('setName', 'setStatus', 'setPrice', 'setWeight');
// $this->_mageRepoProd->save($product);
$this->mMageRepoProd->shouldReceive('save')->once();
/** === Call and asserts === */
$this->obj->update($MAGE_ID, $NAME, $IS_ACTIVE, $PRICE, $WEIGHT);
}
示例2: put
/**
* Update product
*
* @param int $id Id of product to update
* @param array $request_data Datas
* @return int
*
* @url PUT product/{id}
*/
function put($id, $request_data = NULL)
{
if (!DolibarrApiAccess::$user->rights->produit->creer) {
throw new RestException(401);
}
$result = $this->product->fetch($id);
if (!$result) {
throw new RestException(404, 'Product not found');
}
if (!DolibarrApi::_checkAccessToResource('product', $this->product->id)) {
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
}
foreach ($request_data as $field => $value) {
$this->product->{$field} = $value;
}
if ($this->product->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) {
return $this->get($id);
}
return false;
}
示例3: switch
//.........这里部分代码省略.........
if (!empty($ligne[2])) {
$doliprod->status = $ligne[2];
}
$doliprod->status_buy = 1;
if (!empty($ligne[3])) {
$doliprod->description = $ligne[3];
}
if (!empty($ligne[4])) {
$doliprod->price = $ligne[4];
}
if (!empty($ligne[5])) {
$doliprod->tva_tx = $ligne[5];
}
if (!empty($ligne[6])) {
$doliprod->weight = $ligne[6];
}
if (!empty($ligne[7])) {
$doliprod->volume = $ligne[7];
}
if (!empty($ligne[9])) {
$doliprod->barcode = $ligne[9];
}
if (!empty($ligne[9])) {
$doliprod->barcode_type = dol_getIdFromCode($this->db, $ligne[10], 'c_barcode_type', 'libelle', 'rowid');
}
if (!empty($ligne[10])) {
$doliprod->type = $ligne[11];
}
$doliprod->price_base_type = 'HT';
$this->db->begin;
switch ($typeimport) {
case 'C':
if ($pid > 0) {
if ($doliprod->update($pid, $this->user) < 0) {
$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
$error++;
}
if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0) {
$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
$error++;
}
} else {
if ($doliprod->create($this->user) < 0) {
$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error) . "\n";
$error++;
} else {
// image et code barre
if ($ligne[8]) {
$this->add_photo_web($conf->produit->dir_output, $ligne[8], $doliprod->id);
}
/*if ($ligne[9]) {
if ($doliprod->setValueFrom('fk_barcode_type', 2) < 0){
$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; // TODO paramétrer
$error++;
}
if ($doliprod->setValueFrom('barcode', $ligne[9]) < 0 ){
$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n";
$error++;
}
}*/
}
}
break;
/*case 'M':
if ($pid>0)
{
示例4: postProcess
public function postProcess($token = NULL)
{
global $currentIndex;
/* Add a new product */
if (Tools::isSubmit('submitAddproduct') or Tools::isSubmit('submitAddproductAndStay')) {
if ($this->tabAccess['add'] === '1') {
$this->submitAddproduct($token);
} elseif (Tools::getValue('id_product') and $this->tabAccess['edit'] === '1') {
$this->submitAddproduct($token);
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
}
}
/* Delete a product in the download folder */
if (Tools::getValue('deleteVirtualProduct')) {
if ($this->tabAccess['delete'] === '1') {
$this->deleteVirtualProduct();
} else {
$this->_errors[] = Tools::displayError('You do not have permission to delete anything here.');
}
} elseif (Tools::isSubmit('submitAttachments')) {
if ($this->tabAccess['edit'] === '1') {
if ($id = intval(Tools::getValue($this->identifier))) {
if (Attachment::attachToProduct($id, $_POST['attachments'])) {
Tools::redirectAdmin($currentIndex . '&id_product=' . $id . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token));
}
}
}
} elseif (isset($_GET['duplicate' . $this->table])) {
if ($this->tabAccess['add'] === '1') {
if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
$id_product_old = $product->id;
unset($product->id);
unset($product->id_product);
$product->indexed = 0;
if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateQuantityDiscount($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id)) {
if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) {
$this->_errors[] = Tools::displayError('an error occurred while copying images');
} else {
Hook::addProduct($product);
Search::indexation(false);
Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=19&token=' . ($token ? $token : $this->token));
}
} else {
$this->_errors[] = Tools::displayError('an error occurred while creating object');
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
}
} elseif ($id_image = intval(Tools::getValue('id_image')) and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) {
if ($this->tabAccess['edit'] === '1') {
/* Delete product image */
if (isset($_GET['deleteImage'])) {
$image->delete();
deleteImage($image->id_product, $image->id);
if (!Image::getCover($image->id_product)) {
$first_img = Db::getInstance()->getRow('
SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image`
WHERE `id_product` = ' . intval($image->id_product));
Db::getInstance()->Execute('
UPDATE `' . _DB_PREFIX_ . 'image`
SET `cover` = 1
WHERE `id_image` = ' . intval($first_img['id_image']));
}
@unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $image->id_product . '.jpg');
@unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $image->id_product . '.jpg');
Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token));
} elseif (isset($_GET['editImage'])) {
if ($image->cover) {
$_POST['cover'] = 1;
}
$languages = Language::getLanguages();
foreach ($languages as $language) {
if (isset($image->legend[$language['id_lang']])) {
$_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']];
}
}
$_POST['id_image'] = $image->id;
$this->displayForm($token ? $token : $this->token);
} elseif (isset($_GET['coverImage'])) {
Image::deleteCover($image->id_product);
$image->cover = 1;
if (!$image->update()) {
$this->_errors[] = Tools::displayError('Impossible to change the product cover');
} else {
$productId = intval(Tools::getValue('id_product'));
@unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $productId . '.jpg');
@unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $productId . '.jpg');
Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token));
}
} elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) {
$image->positionImage(intval(Tools::getValue('imgPosition')), intval(Tools::getValue('imgDirection')));
Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token));
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
}
} elseif (Tools::isSubmit('submitProductAttribute')) {
if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
//.........这里部分代码省略.........
示例5: sqlInjection
session_start();
require "../includes/checkPermission.php";
require "../../deny/connector.php";
require "class/class.Product.php";
require "../includes/injection.php";
require "../../includes/trackXML.php";
$cate = sqlInjection($_POST['CateID']);
$lable = sqlInjection($_POST['Lable']);
$price = sqlInjection($_POST['Price']);
$artist = sqlInjection($_POST['Artist']);
$producer = sqlInjection($_POST['Producer']);
$year = sqlInjection($_POST['pubYear']);
$disktype = sqlInjection($_POST['DiskType']);
$description = sqlInjection($_POST['Description']);
$tracklist = "";
$image = sqlInjection($_POST['proImage']);
$status = sqlInjection($_POST['ProStatus']);
$id = sqlInjection($_GET['pID']);
$trck = new TrackXML();
$prod = new Product();
if (isset($_POST['trackname']) && isset($_POST['tracklength'])) {
$tracklist = $trck->createXML($_POST['trackname'], $_POST['tracklength']);
}
/*echo $lable."<br>".$cate."<br>".$price
."<br>".$artist."<br>".$producer."<br>".$year."<br>".$disktype."<br>".$description
."<br>".$tracklist."<br>".$image."<br>".$status;*/
$prod->update($id, $lable, $cate, $price, $artist, $producer, $year, $disktype, $description, $tracklist, $image, $status);
echo "<meta http-equiv='refresh' content='0;url=../admincp.php?opt=listproduct'>";
//header("location: ../admincp.php?opt=listproduct");
//exit();
示例6: implode
}
}
$new_tags = implode(",", $new_tags);
if (strlen($new_tags) <= 0) {
$new_tags = $tags;
} else {
$new_tags = $new_tags . "," . $tags;
}
$product->description_short[1] = $new_tags;
} else {
$product->description_short[1] = $tags;
}
$fieldError = $product->validateFields(UNFRIENDLY_ERROR, true);
$langFieldError = $product->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (!empty($fieldError)) {
$product->update();
} else {
$errors[] = "<br/>{$id_product} : " . $langFieldError;
}
$count++;
array_push($product_ids, $id_product);
}
fclose($f);
SolrSearch::updateProducts($product_ids);
echo "Total {$count} rows processed";
echo "<br/>";
echo "<a href='http://www.indusdiva.com/products/{$tagname}'>link</a>";
echo "<br/>" . "--------------------------------------------------";
echo "<br/>Errors";
echo implode("<br/>", $errors);
exit;
示例7: Product
if ($action == 'setstocklimit') {
$object = new Product($db);
$result = $object->fetch($id);
$object->seuil_stock_alerte = $stocklimit;
$result = $object->update($object->id, $user, 0, 'update');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Set desired stock
if ($action == 'setdesiredstock') {
$object = new Product($db);
$result = $object->fetch($id);
$object->desiredstock = $desiredstock;
$result = $object->update($object->id, $user, 0, 'update');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Correct stock
if ($action == "correct_stock" && !$cancel) {
if (!(GETPOST("id_entrepot") > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
$error++;
$action = 'correction';
}
if (!GETPOST("nbpiece")) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
$error++;
示例8: postProcess
//.........这里部分代码省略.........
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->_errors[] = Tools::displayError('File name too long');
}
if (!sizeof($this->_errors)) {
$attachment->add();
Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token));
} else {
$this->_errors[] = Tools::displayError('Invalid file');
}
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (Tools::isSubmit('submitAttachments')) {
if ($this->tabAccess['edit'] === '1') {
if ($id = (int) Tools::getValue($this->identifier)) {
if (Attachment::attachToProduct($id, $_POST['attachments'])) {
Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $id . (isset($_POST['id_category']) ? '&id_category=' . (int) $_POST['id_category'] : '') . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token));
}
}
}
} elseif (isset($_GET['duplicate' . $this->table])) {
if ($this->tabAccess['add'] === '1') {
if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
$id_product_old = $product->id;
unset($product->id);
unset($product->id_product);
$product->indexed = 0;
$product->active = 0;
if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and GroupReduction::duplicateReduction($id_product_old, $product->id) and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateSpecificPrices($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id) and Product::duplicateDownload($id_product_old, $product->id)) {
if ($product->hasAttributes()) {
Product::updateDefaultAttribute($product->id);
}
if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) {
$this->_errors[] = Tools::displayError('An error occurred while copying images.');
} else {
Hook::addProduct($product);
Search::indexation(false, $product->id);
Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=19&token=' . ($token ? $token : $this->token));
}
} else {
$this->_errors[] = Tools::displayError('An error occurred while creating object.');
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (isset($_GET['status']) and Tools::getValue($this->identifier)) {
if ($this->tabAccess['edit'] === '1') {
if (Validate::isLoadedObject($object = $this->loadObject())) {
if ($object->toggleStatus()) {
Tools::redirectAdmin($currentIndex . '&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1' and Tools::getValue('id_product')) ? '&id_category=' . $id_category : '') . '&token=' . $token);
} else {
$this->_errors[] = Tools::displayError('An error occurred while updating status.');
}
} else {
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} elseif (isset($_GET['delete' . $this->table])) {
if ($this->tabAccess['delete'] === '1') {
if (Validate::isLoadedObject($object = $this->loadObject()) and isset($this->fieldImageSettings)) {
示例9: AttrValue
$name_img = $objImg->upload($_FILES, $_POST["photo_now"]);
$objAttr = new AttrValue();
$data_attr = $objAttr->conbine($_POST["attr"], $_POST["val"]);
if (isset($_POST["related"]) and $_POST["related"]) {
$related = array_slice($_POST["related"], 0, 4);
$data_related = serialize($related);
} else {
$data_related = "";
}
require_once "classes/Product.php";
$obj = new Product();
if ($_POST["go"] == "save") {
$fff = $obj->insert($obj->insertSql(), trimStr($_POST["section"]), trimStr($_POST["name"]), trimStr($_POST["nomer"]), trimStr($_POST["brand"]), trimStr($_POST["viscous"]), trimStr($_POST["type"]), trimStr($_POST["volume"]), trimStr($_POST["kol"]), trimStr($_POST["price"]), trimStr($_POST["text"]), $data_related, $data_attr, trimStr($_POST["title"]), trimStr($_POST["description"]), trimStr($_POST["keywords"]), $name_img, trimStr($_POST["img_title"]), trimStr($_POST["img_alt"]));
header("Location: production.php?id=" . $_POST["section"]);
} else {
$obj->update($obj->updateSql(), trimStr($_POST["section"]), trimStr($_POST["name"]), trimStr($_POST["nomer"]), trimStr($_POST["brand"]), trimStr($_POST["viscous"]), trimStr($_POST["type"]), trimStr($_POST["volume"]), trimStr($_POST["kol"]), trimStr($_POST["price"]), trimStr($_POST["text"]), $data_related, $data_attr, trimStr($_POST["title"]), trimStr($_POST["description"]), trimStr($_POST["keywords"]), $name_img, trimStr($_POST["img_title"]), trimStr($_POST["img_alt"]), $_POST['go']);
header("Location: production.php?id=" . $_POST["section"]);
}
}
if (isset($_GET["delete"])) {
$delete = new Delete();
$delete->del($_GET["title"], $_GET["delete"]);
header("Location: production.php?id=" . $_GET["delete"]);
}
require_once "classes/Catalog.php";
$section = new Catalog();
require_once "classes/Product.php";
$objEdit = new Product();
$related = $objEdit->selectAll();
if (isset($_GET["edit"])) {
$record = $objEdit->selectId($_GET['edit']);
示例10: updateProductForPrestashop
/**
* Updates a product on Prestashop.
*
* @param array $product_attributes
* @param integer $id_product
* @param string $url_photo
* @param array $triple_cod_col_siz
* @param integer $language
* @param array $array_combinations
* @return array
* @see $this->isOldNameProductEgualToNewNameProduct
* @see $this->isOldOrNewValueForProduct
* @see $this->controlCategoriesForActivateTheir
* @see $this->updateCombinantionsForPrestashop
*
*/
public function updateProductForPrestashop($product_attributes = array(), $id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language = 1)
{
$product = new Product($id_product);
$is_change_product = false;
$new_name_product = trim($product_attributes["Nome"]);
if (!$this->isOldNameProductEgualToNewNameProduct($product->name, $new_name_product)) {
$product->name = $this->setArrayElementForLinkRewrite($new_name_product, true, $language);
$product->meta_keywords = $new_name_product;
$product->link_rewrite = $this->setArrayElementForLinkRewrite($new_name_product, false, $language);
$is_change_product = true;
}
$new_price = (double) $product_attributes["Prezzo"];
if (!$this->isOldOrNewValueForProduct((double) $product->price, $new_price)) {
$product->price = $new_price;
$is_change_product = true;
}
$new_active = (int) $product_attributes["Attivo"];
$control_category = $this->isOldOrNewValueForProduct((int) $product->active, $new_active);
if (!$control_category) {
$product->active = $new_active;
$is_change_product = true;
}
$new_minimal_quantity = (int) $product_attributes["Qta_min"];
if (!$this->isOldOrNewValueForProduct((int) $product->minimal_quantity, $new_minimal_quantity)) {
$product->minimal_quantity = $new_minimal_quantity;
$is_change_product = true;
}
$new_quantity = (int) $product_attributes["Qta"];
if (!$this->isOldOrNewValueForProduct((int) $product->getQuantity($id_product), $new_quantity)) {
StockAvailable::setQuantity($id_product, 0, $new_quantity);
}
$array_old_features = $product->getFeatures();
$array_features = $product_attributes["Feature"];
$height = false;
$width = false;
foreach ($array_old_features as $array_old_single_features) {
$feature = new FeatureCore((int) $array_old_single_features['id_feature']);
$tmp_feature = $feature->name;
$single_old_feature = $tmp_feature[$language];
$feature_value = new FeatureValueCore((int) $array_old_single_features["id_feature_value"]);
$tmp_feature_value = $feature_value->value;
$single_old_feature_value = $tmp_feature_value[$language];
if ($this->isOldOrNewValueForProduct("Altezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Altezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Altezza"] . " cm");
$feature_value->update();
$height = true;
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Larghezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Larghezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Larghezza"] . " cm");
$feature_value->update();
$width = true;
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Lunghezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Lunghezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Lunghezza"] . " cm");
$feature_value->update();
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Modello", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Modello"])) {
$feature_value->value = array($language => $array_features["Modello"]);
$feature_value->update();
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Linea", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Linea"])) {
$feature_value->value = array($language => $array_features["Linea"]);
$feature_value->update();
$is_change_product = true;
}
}
}
if ($height) {
$product->height = (double) $array_features["Altezza"];
$is_change_product = true;
}
//.........这里部分代码省略.........
示例11: Product
require_once "DataBase/Price.php";
$db_action = var_get_post("db_action", "");
$product = new Product();
$tax = new Tax();
$category = new Category();
$priceset = new Priceset();
$price = new Price();
$group = new Group();
switch ($db_action) {
case "new":
$product->create(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", "")));
$priceset_list = $priceset->get();
for ($i = 0; $i < count($priceset_list); $i++) {
$price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
}
break;
case "edit":
$product->update(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", "")));
$priceset_list = $priceset->get();
for ($i = 0; $i < count($priceset_list); $i++) {
if ($price->exists(var_post("priceset_id_" . $i, ""), var_post("product_id", ""))) {
$price->update(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
} else {
$price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, "")));
}
}
break;
case "delete":
$product->delete(var_get("product_id", ""));
break;
}
示例12: updateOnPOST
/**
* Update Product with user values
*/
public function updateOnPOST()
{
if (Tools::getValue('bettermasseditproduct')) {
$POST = filter_input_array(INPUT_POST);
$products = isset($POST['product']) ? $POST['product'] : array();
//there should be only one product, but in case there're more..
foreach ($products as $id_product => $product) {
$product_obj = new Product($id_product);
//update db and item in $items (to update form)
$product_obj->price = (double) $product['price'];
$product_obj->wholesale_price = (double) $product['wholesale_price'];
//update combinations
foreach ($product['attributes'] as $id_product_attribute => $pattr) {
//update db
$product_obj->updateAttribute($id_product_attribute, (double) $pattr['wholesale_price'], (double) $pattr['price'], $pattr['weight'], $pattr['unit_price_impact'], $pattr['ecotax'], array(), $pattr['reference'], $pattr['ean13'], $pattr['default_on']);
}
$product_obj->update();
return array('code' => 200, 'msg' => 'done');
}
} else {
return array('code' => 500, 'msg' => 'not POST request');
}
}
示例13: hookadminOrder
public function hookadminOrder($params)
{
if (!$this->active) {
return false;
}
global $currentIndex, $smarty;
$table = 'order';
$token = Tools::safeOutput(Tools::getValue('token'));
$errorShipping = 0;
if ($currentIndex == '') {
$currentIndex = 'index.php?controller=' . Tools::safeOutput(Tools::getValue('controller'));
}
$currentIndex .= "&id_order=" . (int) $params['id_order'];
$carrierName = Db::getInstance()->getRow('SELECT c.external_module_name FROM `' . _DB_PREFIX_ . 'carrier` as c, `' . _DB_PREFIX_ . 'orders` as o WHERE c.id_carrier = o.id_carrier AND o.id_order = "' . (int) $params['id_order'] . '"');
if ($carrierName != null && $carrierName['external_module_name'] != $this->_moduleName) {
return false;
}
if (!Configuration::get('TNT_CARRIER_LOGIN') || !Configuration::get('TNT_CARRIER_PASSWORD') || !Configuration::get('TNT_CARRIER_NUMBER_ACCOUNT')) {
$var = array("error" => $this->l("You don't have a TNT account"), 'shipping_numbers' => '', 'sticker' => '');
$smarty->assign('var', $var);
return $this->display(__FILE__, 'tpl/shippingNumber.tpl');
}
if (!Configuration::get('TNT_CARRIER_SHIPPING_COMPANY') || !Configuration::get('TNT_CARRIER_SHIPPING_ADDRESS1') || !Configuration::get('TNT_CARRIER_SHIPPING_ZIPCODE') || !Configuration::get('TNT_CARRIER_SHIPPING_CITY') || !Configuration::get('TNT_CARRIER_SHIPPING_EMAIL') || !Configuration::get('TNT_CARRIER_SHIPPING_PHONE') || !Configuration::get('TNT_CARRIER_SHIPPING_CLOSING')) {
$errorShipping = 1;
}
if ($errorShipping) {
$var = array("error" => $this->l("You didn't give a collect address in the TNT module configuration"), 'shipping_numbers' => '', 'sticker' => '');
$smarty->assign('var', $var);
return $this->display(__FILE__, 'tpl/shippingNumber.tpl');
}
$order = new Order($params['id_order']);
$orderInfoTnt = new OrderInfoTnt((int) $params['id_order']);
$info = $orderInfoTnt->getInfo();
if (is_array($info) && isset($info[3]) && (strlen($info[3]['option']) == 1 || substr($info[3]['option'], 1, 1) == 'S')) {
$smarty->assign('weight', '30');
} else {
$smarty->assign('weight', '20');
}
$products = $order->getProducts();
$productWeight = array();
foreach ($products as $product) {
$p = new Product($product['product_id']);
if ((double) $p->weight == 0 && (!isset($_POST['product_weight_' . $product['product_id']]) || (double) $_POST['product_weight_' . $product['product_id']] <= 0)) {
$productWeight[] = array('id' => $product['product_id'], 'name' => $product['product_name']);
} else {
if (isset($_POST['product_weight_' . $product['product_id']]) && (double) $_POST['product_weight_' . $product['product_id']] > 0) {
$p->weight = (double) $_POST['product_weight_' . $product['product_id']];
$p->update();
}
}
}
if (count($productWeight) > 0) {
$var = array('currentIndex' => $currentIndex, 'table' => $table, 'token' => $token);
$smarty->assign('var', $var);
$smarty->assign('productWeight', $productWeight);
return $this->display(__FILE__, 'tpl/weightForm.tpl');
}
if (!is_array($info) && $info != false) {
$var = array("error" => $info, "date" => '', "dateHidden" => '1', 'currentIndex' => $currentIndex, 'table' => $table, 'token' => $token);
$smarty->assign('var', $var);
return $this->display(__FILE__, 'tpl/formerror.tpl');
}
$pack = new PackageTnt((int) $params['id_order']);
if ($info[0]['shipping_number'] == '' && $pack->getOrder()->hasBeenShipped()) {
$tntWebService = new TntWebService();
try {
if (!isset($_POST['dateErrorOrder'])) {
$orderInfoTnt->getDeleveryDate((int) $params['id_order'], $info);
}
$package = $tntWebService->getPackage($info);
} catch (SoapFault $e) {
$errorFriendly = '';
if (strrpos($e->faultstring, "shippingDate")) {
$dateError = date("Y-m-d");
}
if (strrpos($e->faultstring, "receiver")) {
$receiverError = 1;
$errorFriendly = $this->l('Can you please modify the field') . ' ' . substr($e->faultstring, strpos($e->faultstring, "receiver") + 9, strpos($e->faultstring, "'", strpos($e->faultstring, "receiver") - strpos($e->faultstring, "receiver")) + 1) . ' ' . $this->l('in the box "shipping address" below.');
}
if (strrpos($e->faultstring, "sender")) {
$senderError = 1;
$errorFriendly = $this->l('Can you please modify the field') . ' ' . substr($e->faultstring, strpos($e->faultstring, "sender") + 7, strpos($e->faultstring, "'", strpos($e->faultstring, "sender") - strpos($e->faultstring, "sender")) + 1) . ' ' . $this->l('in your tnt module configuration.');
}
$error = $this->l("Problem : ") . $e->faultstring;
$var = array("error" => $error, "errorFriendly" => $errorFriendly, "date" => isset($dateError) ? $dateError : '', 'currentIndex' => $currentIndex, 'table' => $table, 'token' => $token);
$smarty->assign('var', $var);
return $this->display(__FILE__, 'tpl/formerror.tpl');
}
if (isset($package->Expedition->parcelResponses->parcelNumber)) {
$pack->setShippingNumber($package->Expedition->parcelResponses->parcelNumber);
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tnt_package_history` (`id_order`, `pickup_date`) VALUES ("' . (int) $params['id_order'] . '", "' . pSQL($info[2]['delivery_date']) . '")');
} else {
foreach ($package->Expedition->parcelResponses as $k => $v) {
$pack->setShippingNumber($v->parcelNumber);
}
}
file_put_contents("../modules/" . $this->_moduleName . '/pdf/' . $pack->getOrder()->shipping_number . '.pdf', $package->Expedition->PDFLabels);
}
if ($pack->getShippingNumber() != '') {
$var = array('error' => '', 'shipping_numbers' => $pack->getShippingNumber(), 'sticker' => "../modules/" . $this->_moduleName . '/pdf/' . $pack->getOrder()->shipping_number . '.pdf', 'date' => Db::getInstance()->getValue('SELECT `pickup_date` FROM `' . _DB_PREFIX_ . 'tnt_package_history` WHERE `id_order` = "' . (int) $params['id_order'] . '"'), 'relay' => isset($info[4]) ? $info[4]['name'] . '<br/>' . $info[4]['address'] . '<br/>' . $info[4]['zipcode'] . ' ' . $info[4]['city'] : '', 'place' => Configuration::get('TNT_CARRIER_SHIPPING_ADDRESS1') . " " . Configuration::get('TNT_CARRIER_SHIPPING_ADDRESS2') . "<br/>" . Configuration::get('TNT_CARRIER_SHIPPING_ZIPCODE') . " " . $this->putCityInNormeTnt(Configuration::get('TNT_CARRIER_SHIPPING_CITY')));
//.........这里部分代码省略.........
示例14: testProductUpdate
/**
* testProductUpdate
*
* @param Product $localobject Product
* @return void
*
* @depends testProductFetch
* The depends says test is run only if previous is ok
*/
public function testProductUpdate($localobject)
{
global $conf, $user, $langs, $db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
$localobject->note = 'New note after update';
$result = $localobject->update($localobject->id, $user);
print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n";
$this->assertLessThan($result, 0);
return $localobject;
}
示例15: setPayment
public function setPayment($type)
{
$address_invoice = new Address((int) $this->context->cart->id_address_invoice);
$country = new Country((int) $address_invoice->id_country);
$currency = new Currency((int) $this->context->cart->id_currency);
if (!$this->verifCountryAndCurrency($country, $currency)) {
return false;
}
$klarna = new Klarna();
$klarnaInt = new KlarnaIntegration($klarna);
$klarna->config(Configuration::get('KLARNA_STORE_ID_' . $this->countries[$country->iso_code]['name']), Configuration::get('KLARNA_SECRET_' . $this->countries[$country->iso_code]['name']), $this->countries[$country->iso_code]['code'], $this->countries[$country->iso_code]['langue'], $this->countries[$country->iso_code]['currency'], Configuration::get('KLARNA_MOD'), 'mysql', $this->_getDb());
if ($type == 'invoice' && Configuration::get('KLARNA_INVOICE_FEE_' . $this->countries[$country->iso_code]['name']) > 0 && !$this->isInCart($this->context->cart, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']))) {
$this->context->cart->updateQty(1, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
$productInvoicefee = new Product((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
$productInvoicefee->addStockMvt(1, 1);
$productInvoicefee->update();
}
$this->initReservation($klarna, $this->context->cart, $this->context->customer, isset($_POST['klarna_house_number']) ? htmlentities($_POST['klarna_house_number'], ENT_QUOTES, 'ISO-8859-1') : null, isset($_POST['klarna_house_ext']) ? htmlentities($_POST['klarna_house_ext'], ENT_QUOTES, 'ISO-8859-1') : null);
if (Tools::isSubmit('klarna_pno')) {
$pno = Tools::safeOutput(Tools::getValue('klarna_pno'));
} else {
$day = $_POST['klarna_pno_day'] < 10 ? '0' . (int) $_POST['klarna_pno_day'] : (int) $_POST['klarna_pno_day'];
$month = $_POST['klarna_pno_month'] < 10 ? '0' . (int) $_POST['klarna_pno_month'] : (int) $_POST['klarna_pno_month'];
$pno = Tools::safeOutput($day . $month . Tools::getValue('klarna_pno_year'));
}
$pclass = $type == 'invoice' ? KlarnaPClass::INVOICE : (int) Tools::getValue('paymentAccount');
try {
if ($country->iso_code == 'DE' || $country->iso_code == 'NL') {
if ($this->context->customer->id_gender != 1 && $this->context->customer->id_gender != 2 && $this->context->customer->id_gender != 3) {
$gender = (int) $_POST['klarna_gender'];
$customer = new Customer($this->context->customer->id);
$customer->id_gender = (int) $_POST['klarna_gender'];
$Customer->birthday = (int) $_POST['klarna_pno_year'] . '-' . $month . '-' . $day;
$customer->update();
} else {
$gender = $this->context->customer->id_gender == 1 ? 1 : 0;
}
} else {
$gender = null;
}
$result = $klarnaInt->reserve($pno, $gender, -1, KlarnaFlags::NO_FLAG, (int) $pclass);
// Here we get the reservation number or invoice number
$rno = $result[0];
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'klarna_rno', array('id_cart' => (int) $this->context->cart->id, 'rno' => pSQL($rno), 'pno' => pSQL($pno), 'house_number' => isset($_POST['klarna_house_number']) ? pSQL($_POST['klarna_house_number']) : null, 'house_ext' => isset($_POST['klarna_house_ext']) ? pSQL($_POST['klarna_house_ext']) : null, 'state' => self::RESERVED, 'type' => pSQL($type), 'pclass' => $type == 'invoice' ? null : (int) Tools::getValue('paymentAccount')), 'INSERT');
$updateResult = $klarnaInt->updateOrderNo($rno, (int) $this->context->cart->id);
if ($result[1] == KlarnaFlags::PENDING) {
$this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_PENDING'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key);
} else {
if ($result[1] == KlarnaFlags::ACCEPTED) {
$this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_ACCEPTED'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key);
}
}
$redirect = __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . (int) $this->context->cart->id . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder . '&key=' . $this->context->cart->secure_key;
header('Location: ' . $redirect);
exit;
} catch (Exception $e) {
/*remove invoiceFee if existe*/
$this->context->cart->deleteProduct((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']));
return array('error' => true, 'message' => Tools::safeOutput(utf8_encode($e->getMessage())));
}
}