当前位置: 首页>>代码示例>>PHP>>正文


PHP Hook::updateProduct方法代码示例

本文整理汇总了PHP中Hook::updateProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::updateProduct方法的具体用法?PHP Hook::updateProduct怎么用?PHP Hook::updateProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hook的用法示例。


在下文中一共展示了Hook::updateProduct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: submitAddproduct


//.........这里部分代码省略.........
             if (!Validate::$function($value)) {
                 $this->_errors[] = $this->l('the field') . ' <b>' . call_user_func(array($className, 'displayFieldName'), $field, $className) . '</b> ' . $this->l('is invalid');
             }
         }
     }
     /* Check multilingual fields validity */
     foreach ($rules['validateLang'] as $fieldLang => $function) {
         foreach ($languages as $language) {
             if ($value = Tools::getValue($fieldLang . '_' . $language['id_lang'])) {
                 if (!Validate::$function($value)) {
                     $this->_errors[] = $this->l('the field') . ' <b>' . call_user_func(array($className, 'displayFieldName'), $fieldLang, $className) . ' (' . $language['name'] . ')</b> ' . $this->l('is invalid');
                 }
             }
         }
     }
     $productCats = '';
     if (!isset($_POST['categoryBox']) or !sizeof($_POST['categoryBox'])) {
         $this->_errors[] = $this->l('product must be in at least one Category');
     }
     foreach ($languages as $language) {
         if ($value = Tools::getValue('tags_' . $language['id_lang'])) {
             if (!Validate::isTagsList($value)) {
                 $this->_errors[] = $this->l('Tags list') . ' (' . $language['name'] . ') ' . $this->l('is invalid');
             }
         }
     }
     if (!sizeof($this->_errors)) {
         $id = intval(Tools::getValue('id_' . $this->table));
         $tagError = true;
         /* Update an existing product */
         if (isset($id) and !empty($id)) {
             $object = new $this->className($id);
             if (Validate::isLoadedObject($object)) {
                 $this->copyFromPost($object, $this->table);
                 if ($object->update()) {
                     $this->updateAccessories($object);
                     $this->updateDownloadProduct($object);
                     if (!$this->updatePackItems($object)) {
                         $this->_errors[] = Tools::displayError('an error occurred while adding products to the pack');
                     } elseif (!$object->updateCategories($_POST['categoryBox'], true)) {
                         $this->_errors[] = Tools::displayError('an error occurred while linking object') . ' <b>' . $this->table . '</b> ' . Tools::displayError('to categories');
                     } elseif (!$this->updateTags($languages, $object)) {
                         $this->_errors[] = Tools::displayError('an error occurred while adding tags');
                     } elseif ($id_image = $this->addProductImage($object, Tools::getValue('resizer'))) {
                         Hook::updateProduct($object);
                         Search::indexation(false);
                         if (Tools::getValue('resizer') == 'man' && isset($id_image) and is_int($id_image) and $id_image) {
                             Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&edit=' . strval(Tools::getValue('productCreated')) . '&id_image=' . $id_image . '&imageresize&toconf=4&submitAddAndStay=' . ((Tools::isSubmit('submitAdd' . $this->table . 'AndStay') or Tools::getValue('productCreated') == 'on') ? 'on' : 'off') . '&token=' . ($token ? $token : $this->token));
                         }
                         // Save and stay on same form
                         if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay') or $id_image and $id_image !== true) {
                             Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&conf=4&tabs=' . intval(Tools::getValue('tabs')) . '&token=' . ($token ? $token : $this->token));
                         }
                         // Default behavior (save and back)
                         Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=4&token=' . ($token ? $token : $this->token));
                     }
                 } else {
                     $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b> (' . Db::getInstance()->getMsgError() . ')';
                 }
             } else {
                 $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b> (' . Tools::displayError('cannot load object') . ')';
             }
         } else {
             $object = new $this->className();
             $this->copyFromPost($object, $this->table);
             if ($object->add()) {
                 $this->updateAccessories($object);
                 if (!$this->updatePackItems($object)) {
                     $this->_errors[] = Tools::displayError('an error occurred while adding products to the pack');
                 }
                 $this->updateDownloadProduct($object);
                 if (!sizeof($this->_errors)) {
                     if (!$object->updateCategories($_POST['categoryBox'])) {
                         $this->_errors[] = Tools::displayError('an error occurred while linking object') . ' <b>' . $this->table . '</b> ' . Tools::displayError('to categories');
                     } else {
                         if (!$this->updateTags($languages, $object)) {
                             $this->_errors[] = Tools::displayError('an error occurred while adding tags');
                         } elseif ($id_image = $this->addProductImage($object)) {
                             Hook::addProduct($object);
                             Search::indexation(false);
                             if (Tools::getValue('resizer') == 'man' && isset($id_image) and is_int($id_image) and $id_image) {
                                 Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&id_image=' . $id_image . '&imageresize&toconf=3&submitAddAndStay=' . (Tools::isSubmit('submitAdd' . $this->table . 'AndStay') ? 'on' : 'off') . '&token=' . ($token ? $token : $this->token));
                             }
                             // Save and stay on same form
                             if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
                                 Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&conf=3&tabs=' . intval(Tools::getValue('tabs')) . '&token=' . ($token ? $token : $this->token));
                             }
                             // Default behavior (save and back)
                             Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=3&token=' . ($token ? $token : $this->token));
                         }
                     }
                 } else {
                     $object->delete();
                 }
             } else {
                 $this->_errors[] = Tools::displayError('an error occurred while creating object') . ' <b>' . $this->table . '</b>';
             }
         }
     }
 }
开发者ID:raulgimenez,项目名称:dreamongraphics_shop,代码行数:101,代码来源:AdminProducts.php

示例2: submitAddProduct


//.........这里部分代码省略.........
         if ($value = Tools::getValue('tags_' . $language['id_lang'])) {
             if (!Validate::isTagsList($value)) {
                 $this->_errors[] = $this->l('Tags list') . ' (' . $language['name'] . ') ' . $this->l('is invalid');
             }
         }
     }
     if (!sizeof($this->_errors)) {
         $id = (int) Tools::getValue('id_' . $this->table);
         $tagError = true;
         /* Update an existing product */
         if (isset($id) and !empty($id)) {
             $object = new $this->className($id);
             if (Validate::isLoadedObject($object)) {
                 $this->_removeTaxFromEcotax();
                 $this->copyFromPost($object, $this->table);
                 if ($object->update()) {
                     if ($id_reason = (int) Tools::getValue('id_mvt_reason') and (int) Tools::getValue('mvt_quantity') > 0 and $id_reason > 0) {
                         $reason = new StockMvtReason((int) $id_reason);
                         $qty = Tools::getValue('mvt_quantity') * $reason->sign;
                         if (!$object->addStockMvt($qty, (int) $id_reason, NULL, NULL, (int) $cookie->id_employee)) {
                             $this->_errors[] = Tools::displayError('An error occurred while updating qty.');
                         }
                     }
                     $this->updateAccessories($object);
                     $this->updateDownloadProduct($object);
                     if (!$this->updatePackItems($object)) {
                         $this->_errors[] = Tools::displayError('An error occurred while adding products to the pack.');
                     } elseif (!$object->updateCategories($_POST['categoryBox'], true)) {
                         $this->_errors[] = Tools::displayError('An error occurred while linking object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('To categories');
                     } elseif (!$this->updateTags($languages, $object)) {
                         $this->_errors[] = Tools::displayError('An error occurred while adding tags.');
                     } elseif ($id_image = $this->addProductImage($object, Tools::getValue('resizer'))) {
                         $currentIndex .= '&image_updated=' . (int) Tools::getValue('id_image');
                         Hook::updateProduct($object);
                         Search::indexation(false, $object->id);
                         if (Tools::getValue('resizer') == 'man' && isset($id_image) and is_int($id_image) and $id_image) {
                             Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&edit=' . strval(Tools::getValue('productCreated')) . '&id_image=' . $id_image . '&imageresize&toconf=4&submitAddAndStay=' . ((Tools::isSubmit('submitAdd' . $this->table . 'AndStay') or Tools::getValue('productCreated') == 'on') ? 'on' : 'off') . '&token=' . ($token ? $token : $this->token));
                         }
                         // Save and preview
                         if (Tools::isSubmit('submitAddProductAndPreview')) {
                             $preview_url = $link->getProductLink($this->getFieldValue($object, 'id'), $this->getFieldValue($object, 'link_rewrite', (int) $cookie->id_lang), Category::getLinkRewrite($this->getFieldValue($object, 'id_category_default'), (int) $cookie->id_lang));
                             if (!$object->active) {
                                 $admin_dir = dirname($_SERVER['PHP_SELF']);
                                 $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                                 $token = Tools::encrypt('PreviewProduct' . $object->id);
                                 if (strpos($preview_url, '?') === false) {
                                     $preview_url .= '?';
                                 } else {
                                     $preview_url .= '&';
                                 }
                                 $preview_url .= 'adtoken=' . $token . '&ad=' . $admin_dir;
                             }
                             Tools::redirectAdmin($preview_url);
                         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay') or $id_image and $id_image !== true) {
                             // Save and stay on same form
                             // Save and stay on same form
                             if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
                                 Tools::redirectAdmin($currentIndex . '&id_product=' . $object->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&addproduct&conf=4&tabs=' . (int) Tools::getValue('tabs') . '&token=' . ($token ? $token : $this->token));
                             }
                         }
                         // Default behavior (save and back)
                         Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=4&token=' . ($token ? $token : $this->token) . '&onredirigeici');
                     }
                 } else {
                     $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . '</b> (' . Db::getInstance()->getMsgError() . ')';
                 }
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:67,代码来源:AdminProducts.php


注:本文中的Hook::updateProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。