本文整理汇总了PHP中Attachment::attachToProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::attachToProduct方法的具体用法?PHP Attachment::attachToProduct怎么用?PHP Attachment::attachToProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::attachToProduct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'))))) {
//.........这里部分代码省略.........
示例2: processAttachments
public function processAttachments()
{
if (${${"GLOBALS"}["zmwegqm"]} = (int) Tools::getValue($this->identifier)) {
$rfjgiirc = "id";
${"GLOBALS"}["okwpdejx"] = "attachments";
${${"GLOBALS"}["okwpdejx"]} = trim(Tools::getValue("arrayAttachments"), ",");
${${"GLOBALS"}["xqxiqjoiyypr"]} = explode(",", ${${"GLOBALS"}["xqxiqjoiyypr"]});
if (!Attachment::attachToProduct(${$rfjgiirc}, ${${"GLOBALS"}["xqxiqjoiyypr"]})) {
$this->errors[] = Tools::displayError("There was an error while saving product attachments.");
}
}
}
示例3: postProcess
//.........这里部分代码省略.........
if (isset($_POST['attachment_name_' . (int) $language['id_lang']])) {
$attachment->name[(int) $language['id_lang']] = pSQL($_POST['attachment_name_' . (int) $language['id_lang']]);
}
if (isset($_POST['attachment_description_' . (int) $language['id_lang']])) {
$attachment->description[(int) $language['id_lang']] = pSQL($_POST['attachment_description_' . (int) $language['id_lang']]);
}
}
$attachment->file = $uniqid;
$attachment->mime = $_FILES['attachment_file']['type'];
$attachment->file_name = pSQL($_FILES['attachment_file']['name']);
if (empty($attachment->mime) or Tools::strlen($attachment->mime) > 128) {
$this->_errors[] = Tools::displayError('Invalid file extension');
}
if (!Validate::isGenericName($attachment->file_name)) {
$this->_errors[] = Tools::displayError('Invalid file name');
}
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') {
示例4: importProducts
//.........这里部分代码省略.........
$product->unity = $line[28];
}
if (trim($line[29])) {
$product->unit_price = $line[29];
}
foreach ($languages as $lang) {
$product->description_short[$lang['id_lang']] = $line[30];
$product->description[$lang['id_lang']] = $line[31];
}
if ($line[32]) {
foreach ($languages as $lang) {
Tag::addTags($lang['id_lang'], $product->id, $line[32]);
}
}
foreach ($languages as $lang) {
$product->meta_title[$lang['id_lang']] = $line[33];
$product->meta_keywords[$lang['id_lang']] = $line[34];
$product->meta_description[$lang['id_lang']] = $line[35];
$product->link_rewrite[$lang['id_lang']] = $line[36];
$product->available_now[$lang['id_lang']] = $line[37];
$product->available_later[$lang['id_lang']] = $line[38];
}
$product->available_for_order = $line[39];
$product->available_date = $line[40];
$product->date_add = $line[41];
$product->show_price = $line[42];
// Features import
$features = explode(',', $line[45]);
if ($features) {
foreach ($features as $feature) {
$value = explode(':', $feature);
if ($value[0] && $value[1]) {
Product::addFeatureProductImport((int) $product->id, (int) $value[0], (int) $value[1]);
SpecificPriceRule::applyAllRules(array((int) $product->id));
}
}
}
$product->online_only = trim($line[46]) ? $line[46] : 0;
$product->condition = $line[47];
$product->customizable = trim($line[48]) ? $line[48] : 0;
$product->uploadable_files = trim($line[49]) ? $line[49] : 0;
$product->text_fields = trim($line[50]) ? $line[50] : 0;
if ($product->getType() == Product::PTYPE_VIRTUAL) {
StockAvailable::setProductOutOfStock((int) $product->id, 1);
} else {
StockAvailable::setProductOutOfStock((int) $product->id, (int) $line[51]);
}
$product->id_shop_default = $line[52];
// add product accessories
if ($line[56]) {
$accessories = explode(',', $line[56]);
foreach ($accessories as $accessory) {
$a[]['id'] = $accessory;
}
$product->setWsAccessories($a);
}
// add product carriers
if ($line[57]) {
$carriers = explode(',', $line[57]);
$product->setCarriers($carriers);
}
// add costomisation fields
if (!Tools::isEmpty($line[58]) && class_exists('CustomizationField')) {
$customisation_fields_ids = explode(',', $line[58]);
foreach ($customisation_fields_ids as $customisation_field) {
$result = false;
$customisation_data = explode(':', $customisation_field);
$cf = new CustomizationField();
$cf->id_product = $product->id;
$cf->type = $customisation_data[1];
$cf->required = $customisation_data[2];
foreach ($languages as $lang) {
$cf->name[$lang['id_lang']] = $customisation_data[3] ? $customisation_data[3] : ' ';
}
$cf->force_id = 1;
if (!$result) {
$result = $cf->add();
}
}
}
// add attachments
if ($line[59]) {
$attachments = explode(',', $line[59]);
if (isset($attachments) && count($attachments)) {
Attachment::attachToProduct($product->id, $attachments);
}
}
if ($line[60]) {
$product->date_upd = $line[60];
}
$product->price = $line[61];
$product->force_id = 1;
if (!$res) {
$res = $product->add();
}
}
$this->closeCsvFile($handle);
Search::indexation(true);
return true;
}