Esempio n. 1
0
/**
 * Gets the data for all the products and prompts the user to save it
 *
 * @return null
 */
function Products_adminExport()
{
    $filename = 'webme_products_export_' . date('Y-m-d') . '.csv';
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    // { Get the headers
    $fields = dbAll('describe products');
    $row = '';
    foreach ($fields as $field) {
        $row .= '"_' . $field['Field'] . '",';
    }
    $row .= "\"_categories\",\"_has_images\"\n";
    $contents = $row;
    // }
    // { Get the data
    $results = dbAll('select * from products');
    foreach ($results as $product) {
        $row = '';
        foreach ($fields as $field) {
            $row .= '"' . str_replace('"', '""', $product[$field['Field']]) . '",';
        }
        $cats = ProductsCategoriesProducts::getByProductId($product['id']);
        $catsArr = array();
        foreach ($cats as $cat) {
            $vals = ProductCategory::getInstance($cat)->vals;
            $info = array('name' => $vals['name'], 'parent_id' => $vals['parent_id']);
            $thisCat = '';
            $catName = $info['name'];
            $thisCat .= $catName;
            $parent = $info['parent_id'];
            while ($parent > 0) {
                $vals = ProductCategory::getInstance($parent)->vals;
                $info = array('name' => $vals['name'], 'parent_id' => $vals['parent_id']);
                $parentName = $info['name'];
                $thisCat = $parentName . '>' . $thisCat;
                $parent = $info['parent_id'];
            }
            $catsArr[] = $thisCat;
        }
        $row .= '"' . join('|', $catsArr) . '"';
        // { has images
        $has_images = 0;
        if ($product['images_directory'] && @is_dir(USERBASE . '/f/' . $product['images_directory'])) {
            $dir = new DirectoryIterator(USERBASE . '/f/' . $product['images_directory']);
            foreach ($dir as $f) {
                if ($f->isDot()) {
                    continue;
                }
                if ($f->isFile()) {
                    $has_images++;
                }
            }
        }
        $row .= ',"' . ($has_images ? 'Yes' : 'No') . '"';
        // }
        $contents .= $row . "\n";
    }
    echo $contents;
    // }
    Core_quit();
}
Esempio n. 2
0
 /**
  * get the relative URL of a page for showing this product
  *
  * @return string URL of the product's page
  */
 function getRelativeUrl()
 {
     global $PAGEDATA;
     if (isset($this->relativeUrl) && $this->relativeUrl) {
         return $this->relativeUrl;
     }
     // { if this product is disabled, then it can only be shown on special pages
     if ($this->vals['enabled'] == '0') {
         $pid = dbOne('select page_id from page_vars' . ' where name="products_filter_by_status" and value in (1, 2)', 'page_id');
         $page = Page::getInstance($pid);
         if (!$page) {
             return '/';
         }
         return $page->getRelativeUrl() . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link);
     }
     // }
     // { Does the product have a page assigned to display the product?
     $pageID = dbOne('select page_id from page_vars where name="products_product_to_show" ' . 'and value=' . $this->id . ' limit 1', 'page_id', 'page_vars');
     if ($pageID) {
         $this->relativeUrl = Page::getInstance($pageID)->getRelativeUrl();
         return $this->relativeUrl;
     }
     // }
     // { Is there a page intended to display its category?
     $productCats = ProductsCategoriesProducts::getByProductId($this->id);
     $productCats[] = $this->default_category;
     $pcats = array();
     foreach ($productCats as $cid) {
         $cat = ProductCategory::getInstance($cid);
         if ($cat) {
             $url = $cat->getRelativeUrl();
             return $url . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link);
         }
     }
     // }
     $cat = 0;
     if (@$_REQUEST['product_cid']) {
         $cat = (int) $_REQUEST['product_cid'];
     }
     if ($cat) {
         $category = ProductCategory::getInstance($cat);
         if ($category) {
             $catdir = $category->getRelativeUrl();
         } else {
             $catdir = '/missing-category-' . $cat;
             $pids = ProductsCategoriesProducts::getByCategoryId($cat);
             ProductsCategoriesProducts::deleteByCategoryId($cat);
             Products_categoriesRecount($pids);
             return $this->getRelativeUrl();
         }
         return $catdir . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link);
     }
     if (preg_match('/^products(\\||$)/', $PAGEDATA->type)) {
         return $PAGEDATA->getRelativeUrl() . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link);
     }
     $this->relativeUrl = '/_r?type=products&product_id=' . $this->id;
     return $this->relativeUrl;
 }
Esempio n. 3
0
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);
}
Esempio n. 4
0
            $detail = @$pdata['stockcontrol_details'];
            if (!$detail) {
                $detail = '[]';
            }
            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'];