$page = implode ('', file ("" .$product_sku. ";vendor=" .$mf_name. ";shopname=url;lang=UK"));
$mysite = $_SERVER['PHP_SELF'].'?link='; // request this page
$page = preg_replace("/<a href=\"(.*)\">/i", "<a href=\"$mysite\\1\">", $page);
echo $page;

Now i can't find a way to get this work.
I need product_sku and mf_name to be collected from a joomla vm site and implode this external link into my joomla vm site.

Any help?

Dani AI

Generated

— scraping an external HTML page into Joomla is fragile; it is better to fetch the data reliably and to get the SKU/manufacturer from VirtueMart itself where possible. is right that file_get_contents avoids file() splitting by newlines, but production code should use a proper HTTP client (cURL or Joomla's HTTP layer) with timeouts, error checks and URL-encoding of parameters (see PHP docs for file_get_contents and cURL). (https://www.php.net/manual/en/function.file-get-contents.php) (https://www.php.net/manual/en/book.curl.php)

Suggested workflow to implement inside a Joomla module/override:

  1. Identify the current product id used on the page (check the request or the view’s product object).
  2. Load the product via VirtueMart’s product API/model and read the SKU property (common property names include product_sku).
  3. If the product carries a manufacturer id, load the manufacturer record via the manufacturer model to get its name (commonly mf_name).
  4. Build the remote URL with properly encoded query values, fetch with cURL/JHttp, and parse the returned content. Parsing HTML should use a DOM parser (DOMDocument) rather than brittle regexes.

Troubleshooting tips: dump the product object to inspect available fields; test the remote URL from the server (to catch firewall/SSL issues); check allow_url_fopen if using file_get_contents; log HTTP status and response body before attempting replacements. For API/model details consult the VirtueMart and Joomla documentation. (https://docs.virtuemart.net/) (https://docs.joomla.org/)

Recommended Answers

All 2 Replies

Why are you using file , just use file_get_contents which doesn't split by newline

I don't know much about coding and i found this peace of code on the internet for external pages to load on your site.

The code is working fine for oscommerce shops. But i was wundering if someone can help me out to change the code so it will work in joomla virtuemart.

I'm looking for the right code to extract
product sku $product_sku and
manufacturer name $mf_name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.