function OnlineStoreEbay_adminPublish() { list($sess, $vs, $userToken) = OnlineStoreEbay_sessionStart(); $price = (double) $_REQUEST['buy_now_price']; $bidsStartPrice = (double) $_REQUEST['bids_start_at']; $countryFrom = $vs['ebay_country_from']; $currency = 'EUR'; $dispatchDays = $vs['ebay_dispatch_days']; $productId = (int) $_REQUEST['id']; $product = Product::getInstance($productId); $description = $product->get('description'); $paypalAddress = $vs['ebay_paypal_address']; $categoryId = 0; $rs = ProductsCategoriesProducts::getByProductId($productId); foreach ($rs as $r) { $c = ProductCategory::getInstance($r); if ($c->vals['ebay_id']) { $categoryId = $c->vals['ebay_id']; break; } } $howMany = (int) $_REQUEST['quantity']; $returnsPolicy = $vs['ebay_returns_policy']; $title = $product->get('name'); $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">' . '<ErrorLanguage>en_US</ErrorLanguage><WarningLevel>High</WarningLevel>'; // { main details $xml .= '<Item>' . '<ApplicationData>{"productId":' . $productId . '}</ApplicationData>' . '<Site>Ireland</Site>' . '<Title>' . htmlspecialchars($title) . '</Title>'; // } // { price $xml .= '<Currency>' . $currency . '</Currency>'; if ($bidsStartPrice >= 0.01) { $xml .= '<BuyItNowPrice>' . sprintf('%.2f', $price) . '</BuyItNowPrice>' . '<StartPrice>' . sprintf('%.2f', $bidsStartPrice) . '</StartPrice>' . '<ListingType>Chinese</ListingType>'; } else { $xml .= '<StartPrice>' . sprintf('%.2f', $price) . '</StartPrice>' . '<ListingType>FixedPriceItem</ListingType>'; } // } // { pictures $xml .= '<PictureDetails>'; $images = $product->getAllImages(); $siteurl = isset($GLOBALS['DBVARS']['cdn']) && $GLOBALS['DBVARS']['cdn'] ? $GLOBALS['DBVARS']['cdn'] : $_SERVER['HTTP_HOST']; $xml .= '<PictureURL>' . str_replace(' ', '%20', 'http://' . $siteurl . '/f' . $product->getDefaultImage()) . '</PictureURL>'; $images_html = ''; foreach ($images as $img) { $imgUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/f' . $img; $xml .= '<PictureURL>' . str_replace(' ', '%20', $imgUrl) . '</PictureURL>'; $images_html .= '<img src="' . $imgUrl . '"/>'; } $xml .= '</PictureDetails>'; // } // { other main stuff $xml .= '<CategoryMappingAllowed>true</CategoryMappingAllowed>' . '<ConditionID>1000</ConditionID>' . '<Country>' . $countryFrom . '</Country>' . '<Location>China</Location>' . '<Description>' . htmlspecialchars($description . $images_html . '<br/><p>' . nl2br($vs['ebay_description_afterword']) . '</p>') . '</Description>' . '<DispatchTimeMax>' . $dispatchDays . '</DispatchTimeMax>' . '<PayPalEmailAddress>' . $paypalAddress . '</PayPalEmailAddress>' . '<ListingDuration>Days_30</ListingDuration>' . '<PaymentMethods>PayPal</PaymentMethods>'; // } $xml .= '<PrimaryCategory><CategoryID>' . $categoryId . '</CategoryID></PrimaryCategory>' . '<Quantity>' . $howMany . '</Quantity>' . '<ReturnPolicy><ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>' . '<ReturnsWithinOption>Days_14</ReturnsWithinOption>' . '<Description>' . htmlspecialchars($returnsPolicy) . '</Description>' . '<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>' . '</ReturnPolicy>' . '<ShippingDetails>' . '<InternationalShippingServiceOption>' . '<ShippingService>IE_SellersStandardRateInternational</ShippingService>' . '<ShippingServiceAdditionalCost currencyID="EUR">0</ShippingServiceAdditionalCost><ShippingServiceCost currencyID="EUR">0</ShippingServiceCost><ShippingServicePriority>0</ShippingServicePriority><ShipToLocation>Europe</ShipToLocation></InternationalShippingServiceOption>' . '<ShippingServiceOptions><FreeShipping>true</FreeShipping>' . '<ShippingService>IE_EconomyDeliveryFromAbroad</ShippingService>' . '<ShippingServiceAdditionalCost currencyID="EUR">0</ShippingServiceAdditionalCost>' . '</ShippingServiceOptions>' . '</ShippingDetails>' . '<ItemSpecifics>' . '<NameValueList><Name>Brand</Name><Value>Generic</Value></NameValueList>' . '<NameValueList><Name>Size</Name><Value>Free Size</Value></NameValueList>' . '</ItemSpecifics>' . '</Item>' . '<RequesterCredentials>' . '<eBayAuthToken>' . $userToken . '</eBayAuthToken>' . '</RequesterCredentials>' . '<WarningLevel>High</WarningLevel>' . '</AddItemRequest>'; $xmlstr = $sess->sendHttpRequest($xml); $reply = new SimpleXMLElement($xmlstr); $errors = isset($reply->Errors) ? $reply->Errors : false; return array('sent' => $xml, 'reply' => new SimpleXMLElement($xmlstr), 'errors' => $errors); }
function Products_adminProductCategoryContainsUpdate() { $id = (int) $_REQUEST['id']; if (!$id) { $id = dbOne('select id from products order by id limit 1', 'id'); } $rs = dbAll('select * from products_categories_products where product_id=' . $id); foreach ($rs as $r) { $cat = ProductCategory::getInstance($r['category_id']); if ($cat) { $cat->containsDel($r['product_id'], $r['category_id']); $cat->containsAdd($r['product_id'], $r['category_id']); } else { dbQuery('delete from products_categories_products where product_id=' . $id . ' and category_id=' . $r['category_id']); } } echo $id; $id = dbOne('select id from products where id>' . $id . ' order by id limit 1', 'id'); if ($id) { echo '<script>setTimeout(function() {document.location="./id=' . $id . '";}, 1);</script>'; } else { echo '<br/>DONE'; } exit; }
static function insert($cid, $pid) { $cid = (int) $cid; $pid = (int) $pid; $cat = ProductCategory::getInstance($cid); if (!$cat) { return; } dbQuery('insert into products_categories_products' . ' set category_id=' . $cid . ', product_id=' . $pid); $cat->containsAdd($pid, $cid); self::clearCache(); }
/** * render a list of products to HTML * * @param object $PAGEDATA the page object * @param int $start offset * @param int $limit how many products to show * @param string $order_by what field to order the search by * @param int $order_dir order ascending or descending * @param int $limit_start lowest $start offset allowed * @param int $enabledFilter whether to allow enabled/disabled products * * @return string the HTML of the products list */ function render($PAGEDATA, $start = 0, $limit = 0, $order_by = '', $order_dir = 0, $limit_start = 0, $enabledFilter = 0) { global $cdnprefix; $c = ''; // { sort based on $order_by $md5 = md5('ps-sorted-' . join(',', $this->product_ids) . '|' . $order_by . '|' . $order_dir . '|' . $enabledFilter); $tmpprods = -1; if ($order_dir != 2) { $tmpprods = Core_cacheLoad('products', $md5, -1); } if ($tmpprods == -1) { if ($order_by != '') { $native = substr($order_by, 0, 1) === '_'; $tmpprods1 = array(); $prods = $this->product_ids; $sql = 'select id'; if (!$native) { $sql .= ',data_fields'; } $sql .= ' from products where id in (' . join(', ', $this->product_ids) . ')'; if ($enabledFilter == 0) { $sql .= ' and enabled'; } if ($enabledFilter == 1) { } if ($enabledFilter == 2) { $sql .= ' and !enabled'; } if ($native) { $sql .= ' order by ' . substr($order_by, 1, strlen($order_by) - 1); if ($order_dir == 1) { $sql .= ' desc'; } } $values = dbAll($sql, '', 'products'); if ($native) { $tmpprods = array(); if (is_array($values)) { foreach ($values as $v) { $tmpprods[] = $v['id']; } if ($order_dir == 2) { shuffle($tmpprods); } } } else { if (is_array($values)) { foreach ($values as $v) { $vals = json_decode($v['data_fields'], true); $key2 = ''; foreach ($vals as $v2) { if ($v2['n'] == $order_by) { $key2 = __FromJSON($v2['v']); } } if (!isset($tmpprods1[$key2])) { $tmpprods1[$key2] = array(); } $tmpprods1[$key2][] = $v['id']; } } if ($order_dir == 1) { krsort($tmpprods1); } else { if ($order_dir == 0) { ksort($tmpprods1); } else { if ($order_dir == 2) { shuffle($tmpprods1); } } } $tmpprods = array(); foreach ($tmpprods1 as $pids) { foreach ($pids as $pid) { $tmpprods[] = $pid; } } foreach ($prods as $key => $pid) { $tmpprods[] = $pid; } } } else { $tmpprods = $this->product_ids; } Core_cacheSave('products', $md5, $tmpprods); } // } // { sanitise the limits $cnt = count($tmpprods); if (!$limit) { $limit = $cnt; $start = 0; } else { if ($start && $start >= count($this->product_ids)) { $start = $cnt - $limit; } } // } // { build array of items $prevnext = ''; $total_found = count($tmpprods); if ($cnt == $limit) { $prods =& $tmpprods; } else { $prods = array(); for ($i = $start; $i < $limit + $start; ++$i) { if (isset($tmpprods[$i])) { $prods[] = $tmpprods[$i]; } } $prefix = ''; if ($PAGEDATA->vars['products_what_to_show'] == 2) { $cat = ProductCategory::getInstance($PAGEDATA->vars['products_category_to_show']); if ($cat) { $prefix = $cat->getRelativeUrl(); } } if (!$prefix) { $prefix = $PAGEDATA->getRelativeUrl(); } if ($start > $limit_start) { $prevnext .= '<a class="products-prev" href="' . $prefix . '?start=' . ($start - $limit) . '">' . __('Previous') . '</a>'; } if ($limit && $start + $limit < $cnt) { if ($start) { $prevnext .= ' | '; } $prevnext .= '<a class="products-next" href="' . $prefix . '?start=' . ($start + $limit) . '">' . __('Next') . '</a>'; } } $prevnext = '<div class="products-pagination">' . $prevnext . '</div>'; // } // { see if there are search results if (isset($PAGEDATA->vars['products_add_a_search_box']) && $PAGEDATA->vars['products_add_a_search_box']) { $c .= '<div class="products-num-results">' . __('<strong>%1</strong> results found.', array($total_found), 'core') . '</div>'; } // } if (!isset($PAGEDATA->vars['products_show_multiple_with'])) { $PAGEDATA->vars['products_show_multiple_with'] = 0; } $prods = array_unique($prods); switch ($PAGEDATA->vars['products_show_multiple_with']) { case 1: // { horizontal table, headers on top $c .= Product_datatableMultiple($prods, 'horizontal'); break; // } // } case 2: // { vertical table, headers on left $c .= Product_datatableMultiple($prods, 'vertical'); break; // } // } case 3: // { map view WW_addScript('products'); WW_addCSS('/ww.plugins/products/products.css'); return '<div id="products-mapview"></div>'; // } // } case 4: // { carousel WW_addScript('products'); $c = '<div id="products-carousel"><ul id="products-carousel-slider">'; foreach ($prods as $pid) { $product = Product::getInstance($pid, false, $enabledFilter); if ($product && isset($product->id) && $product->id) { $typeID = $product->get('product_type_id'); $type = ProductType::getInstance($typeID); if (!$type) { $c .= '<li>' . __('Missing Product Type: %1', array($typeID), 'core') . '</li>'; } else { $c .= '<li id="products-' . $product->id . '" class="products-product">' . $type->render($product, 'multiview', 0) . '</li>'; } } } $c .= '</ul></div>'; WW_addScript('/j/jsor-jcarousel-7bb2e0a/jquery.jcarousel.min.js'); WW_addCSS('/ww.plugins/products/products.css'); return $c; // } // } default: // { use template if (count($prods)) { // display the first item's header $product = Product::getInstance($prods[0], false, $enabledFilter); $type = ProductType::getInstance($product->get('product_type_id')); if ($type) { $smarty = Products_setupSmarty(); $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_header'); } } foreach ($prods as $pid) { $product = Product::getInstance($pid, false, $enabledFilter); if ($product && isset($product->id) && $product->id) { $typeID = $product->get('product_type_id'); $type = ProductType::getInstance($typeID); if (!$type) { $c .= __('Missing Product Type: %1', array($typeID), 'core'); } else { if (isset($_REQUEST['product_id'])) { $c .= $type->render($product, 'singleview'); } else { $c .= $type->render($product, 'multiview'); } } } } if (isset($type) && $type && count($prods)) { // display first item's header $smarty = Products_setupSmarty(); $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_footer'); } // } } $categories = ''; if (!isset($_REQUEST['products-search']) && isset($this->subCategories) && count($this->subCategories) && !@$PAGEDATA->vars['products_dont_show_sub_categories']) { $categories = '<ul class="products-categories categories">'; foreach ($this->subCategories as $cr) { $cat = ProductCategory::getInstance($cr['id']); $categories .= '<li><a href="' . $cat->getRelativeUrl() . '">'; $icon = '/products/categories/' . $cr['id'] . '/icon.png'; if (file_exists(USERBASE . 'f' . $icon)) { $subcatW = (int) $cat->vals['thumbsize_w']; $subcatH = (int) $cat->vals['thumbsize_h']; $categories .= '<img src="' . $cdnprefix . '/a/f=getImg/w=' . $subcatW . '/h=' . $subcatH . '/fmt=' . filemtime(USERBASE . 'f' . $icon) . $icon . '"/>'; } $categories .= '<span>' . htmlspecialchars($cr['name']) . '</span>' . '</a></li>'; } $categories .= '</ul>'; } return $categories . $prevnext . '<div class="products">' . $c . '</div>' . $prevnext; }
/** * get details about a specific product type * * @return array the product type details */ function Products_typeGet() { $id = (int) @$_REQUEST['id']; $r = Core_cacheLoad('products', 'productTypeDetails_' . $id, -1); if ($r === -1) { $r = dbRow("select * from products_types where id={$id}"); $r['default_category_name'] = ProductCategory::getInstance($r['default_category'])->vals['name']; $r['data_fields'] = json_decode($r['data_fields']); Core_cacheSave('products', 'productTypeDetails_' . $id, $r); } return $r; }
echo '<select name="widget_type">'; foreach ($types as $t) { echo '<option'; if ($type == $t) { echo ' selected="selected"'; } echo '>' . $t . '</option>'; } echo '</select><br/>'; // } // { parent category echo '<strong>Parent Category</strong><br />' . '<select name="parent_cat" id="parent_cat_' . $id . '">'; if (!isset($_REQUEST['parent_cat'])) { echo '<option value="0"> -- please choose -- </option>'; } else { echo '<option value="' . (int) $_REQUEST['parent_cat'] . '">' . ProductCategory::getInstance((int) $_REQUEST['parent_cat'])->vals['name'] . '</option>'; } echo '</select><br/>'; // } // { show products echo '<div class="show-products"><strong>Show Products</strong><br/>' . '<select name="show_products"><option value="0">No</option>' . '<option value="1"'; if (isset($_REQUEST['show_products']) && $_REQUEST['show_products'] == '1') { echo ' selected="selected"'; } echo '>Yes</select></div>'; // } // { diameter echo '<div class="diameter"><strong>Diameter (for Pie Chart)</strong>'; $diameter = isset($_REQUEST['diameter']) && $_REQUEST['diameter'] ? (int) $_REQUEST['diameter'] : 280; echo '<input name="diameter" value="' . htmlspecialchars($diameter) . '" /></div>'; // }
} echo '<table id="stockcontrol-complex"></table><script>' . 'window.stockcontrol_detail=' . $detail . ';window.stockcontrol_options=["' . join('", "', $options) . '"];</script><a href="#" id="' . 'stockcontrol-addrow">add row</a>' . '<p>' . __('To remove rows, set their options to "-- Choose --" and save the' . ' product.') . '</p>'; } // } echo '</div>'; } } // } Core_trigger('products-show-edit-form-tabs', array($pdata, $product_type)); // { categories echo '<h2>' . __('Categories') . '</h2><div id="categories"><p>' . __('At least one category must be chosen.') . '</p>'; // { add selected categories to the list $rs = ProductsCategoriesProducts::getByProductId($id); echo '<ul id="categories-wrapper">'; foreach ($rs as $r) { $cat = ProductCategory::getInstance($r); if (!$cat) { continue; } echo '<li><input type="checkbox" name="product_categories[' . $cat->vals['id'] . ']" checked="checked"/>' . $cat->getBreadcrumbs() . '</li>'; } echo '</ul><button id="category-add">Add Category</button>'; // } $cid = (int) @$pdata['default_category']; if (!$cid) { $cid = 1; } $default_category = Product::getInstance($cid)->vals['name']; echo '<br/><label>Default Category: <select name="products_default_category">' . '<option value="' . (int) @$pdata['products_default_category'] . '">' . $default_category . '</option></select></label>'; echo '</div>'; // }