public static function product($id) { $product = oc::model('catalog_product')->getProduct($id); $product['description'] = html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8'); $categories = oc::model('catalog_product')->getCategories($id); $product['categories'] = array(); foreach ($categories as $c) { if ($c['main_category']) { $product['main_category'] = $c['category_id']; } else { $product['categories'][] = $c['category_id']; } } if (!array_key_exists('main_category', $product)) { $product['main_category'] = count($product['categories']) ? reset($product['categories']) : 1; } $product['orig_price'] = oc::exec2var('SELECT price FROM ' . DB_PREFIX . 'product WHERE product_id=' . (int) $id); $product['images'] = array(); if (isset($product['image'])) { $product['images'][] = $product['image']; } $images = oc::model('catalog_product')->getProductImages($id); foreach ($images as $img) { $product['images'][] = $img['image']; } $product['discounts'] = array(); $discounts = oc::model('catalog_product')->getProductDiscounts($id); foreach ($discounts as $discount) { $product['discounts'][] = array('quantity' => $discount['quantity'], 'price' => $discount['price']); } $product['attributes'] = self::product_attributes($id); $product['allreviews'] = array(); $reviews = oc::model('catalog_review')->getReviewsByProductId($id); foreach ($reviews as $review) { $product['allreviews'][] = array('id' => $review['review_id'], 'author_name' => $review['author'], 'rating' => $review['rating'], 'text' => $review['text'], 'date' => $review['date_added']); } $product['related'] = oc::model('catalog_product')->getProductRelated($id); foreach ($product['related'] as &$p) { $p['href'] = oc::$url->link('product/product', '&product_id=' . $p['product_id']); } return $product; }
$groupID = getGroupID(trim($_REQUEST['attribute_group_name'])); $aModel = oc::model('catalog_attribute'); // $lines = preg_split("/<br>/",str_replace('&nbsp;','',trim($_REQUEST['attribute_list']))); // $lines = preg_split("/<\/tr>/",str_replace('&nbsp;','',trim($_REQUEST['attribute_list']))); $lines = preg_split("/\n+/", str_replace('&nbsp;', '', trim($_REQUEST['attribute_list']))); foreach ($lines as $line) { // if (preg_match("/^([^:]+):\s*<strong>([^&]+)<\/strong>/", trim($line), $found)) { // if (preg_match("/^<tr>\s*<td>([^&]+)<\/td>\s*<td>([^&]+)<\/td>/", trim($line), $found)) { if (preg_match("/^([^=]+)\\s*=\\s*([^=]+\$)/", trim($line), $found)) { $name = trim($found[1]); $value = trim($found[2]); $aID = false; $exists = $aModel->getAttributes(array('filter_name' => $name)); if (!$exists) { echo "Add attribute: {$name} = {$value} <br>"; $sortOrder = oc::exec2var("SELECT MAX(sort_order) FROM oc_attribute WHERE attribute_group_id={$groupID}"); $sortOrder = $sortOrder ? $sortOrder + 10 : 10; $aModel->addAttribute(array('attribute_group_id' => $groupID, 'sort_order' => $sortOrder, 'attribute_description' => array(1 => array('name' => $name)))); $added = $aModel->getAttributes(array('filter_name' => $name)); $aID = (int) $added[0]['attribute_id']; } else { $aID = (int) $exists[0]['attribute_id']; } $pid = (int) $_REQUEST['product_id']; oc::exec("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int) $pid . "' AND attribute_id = '" . (int) $aID . "'"); oc::exec("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int) $pid . "', attribute_id = '" . (int) $aID . "', language_id = 1 , text = '" . oc::db()->escape($value) . "'"); } } } ?>