Soft Solutions4U Soft Solutions4U Soft Solutions4U Soft Solutions4U
"Currently we are not accepting any more applications for any job post"
Login Logout
  • Home
    • About Us
    • Why Us?
    • Our Approach
    • Clients-Partners
    • Blog
  • Projects
  • Expertise
    • Technology
    • White Paper
      • Vue.js
        • Solving problems of Single Page Apps with Vue.js
      • PrestaShop
        • How to migrate to PrestaShop from Joomla
        • How to combine delivery notification emails
        • Printable-Voucher-download-button
        • How-to-sell-events-in-PrestaShop
      • TYPO3
        • Corporate TYPO3 Template Installation
        • TYPO3-Restaurant-Template-Installation
        • TYPO3 Template Customization
        • How to Add a New Section in TYPO3 template
        • How to change the name of a section?
      • WordPress
        • Wix vs WordPress
  • Service
    • Ss4uCRM-SuiteCRM
    • TYPO3 Development
    • WordPress Development
    • PrestaShop
    • Payrexx Integration
    • Laravel Development
    • Shopify Development
  • Testimonials
  • Contact
    • Contact Us
    • Project Planner
    • Careers
  • EN
    • DE
    • FR
    • IT
Soft Solutions4U Soft Solutions4U
  • Home
    • About Us
    • Why Us?
    • Our Approach
    • Clients-Partners
    • Blog
  • Projects
  • Expertise
    • Technology
    • White Paper
      • Vue.js
        • Solving problems of Single Page Apps with Vue.js
      • PrestaShop
        • How to migrate to PrestaShop from Joomla
        • How to combine delivery notification emails
        • Printable-Voucher-download-button
        • How-to-sell-events-in-PrestaShop
      • TYPO3
        • Corporate TYPO3 Template Installation
        • TYPO3-Restaurant-Template-Installation
        • TYPO3 Template Customization
        • How to Add a New Section in TYPO3 template
        • How to change the name of a section?
      • WordPress
        • Wix vs WordPress
  • Service
    • Ss4uCRM-SuiteCRM
    • TYPO3 Development
    • WordPress Development
    • PrestaShop
    • Payrexx Integration
    • Laravel Development
    • Shopify Development
  • Testimonials
  • Contact
    • Contact Us
    • Project Planner
    • Careers
  • EN
    • DE
    • FR
    • IT
  • EN
  • DE
  • FR
  • IT

"Currently we are not accepting any more applications for any job post"

Login Logout
Dec 12

Migrating a Joomla website to PrestaShop

  • December 12, 2018
  • Shar
  • No Comments
  • PrestaShop

Challenges faced while migrating a ECommerce store from Joomla extension-JoomShopping to PrestaShop.

Challenge: 1

All the Products and Categories from the JoomShopping needed to be migrated into PrestaShop 1.7.3 CMS. We searched through the internet, there was no tool found. So we made a standalone script to migrate the entries from JoomShopping to PrestaShop.

This is how we implemented the standalone script:

  • We analyzed the Product and Category table structure of JoomShopping and PrestaShop, PrestaShop have possibility to store all the details of Product and Category from JoomShopping. Managing details of Product and Categories are same in both and only difference is table structure.
  • For migration process, we created a standalone PHP script, for every run it will migrate all the future Products and Categories which means it will not migrate already added entries.

First step:

  • We need the following JoomShopping module database tables for migration process:
    1. joom_jshopping_attr
    2. joom_jshopping_attr_values
    3. joom_jshopping_categories
    4. joom_jshopping_products
    5. joom_jshopping_products_attr2
    6. joom_jshopping_products_images
    7. joom_jshopping_products_to_categories
  • The script imported all the above tables into the PrestaShop CMS

Second step:

  • Once Category migration starts, the following code may be used for adding a new Category in PrestaShop :
    $category = new Category;
    $category->active = joom_jshopping_categories::category_publish;
    $category->id_parent = joom_jshopping_categories::category_parent_id;(Here, parent category ID from Prestashop)
    $category->id_shop_default = ;
    $category->name = joom_jshopping_categories::name_de-DE;
    $category->link_rewrite = joom_jshopping_categories::alias_de-DE;
    $category->meta_title   = joom_jshopping_categories::meta_title_de-DE;
    $category->meta_description = joom_jshopping_categories::meta_description_de-DE;
    $category->meta_keywords = joom_jshopping_categories::meta_keyword_de-DE;
    $category->description = joom_jshopping_categories::description_de-DE;
    $category->date_add = joom_jshopping_categories::category_add_date;
    $category->add();
    // For adding category images
    AdminImportController::copyImage(
      $category->id,
      null,
      joom_jshopping_categories::category_image,
      'categories'
    );

Third step:

  • After Category migration, the Product migration will start. For adding a New Product in PrestaShop use the following code:
    $product = new Product();
    $product->name = joom_jshopping_products::name_de-DE;
    $product->link_rewrite = joom_jshopping_products::alias_de-DE;
    $product->description = joom_jshopping_products::description_de-DE;
    $product->description_short = joom_jshopping_products::short_description_de-DE;
    $product->meta_description = joom_jshopping_products::meta_description_de-DE;
    $product->meta_keywords = joom_jshopping_products::meta_keyword_de-DE;
    $product->meta_title = joom_jshopping_products::meta_title_de-DE;
    $product->price = joom_jshopping_products::product_price;
    $product->quantity = joom_jshopping_products::product_quantity;
    $product->wholesale_price = joom_jshopping_products::product_buy_price;
    $product->date_add = joom_jshopping_products::product_date_added;
    $product->date_upd = joom_jshopping_products::date_modify;
    // To assign multiple Categories
    $product->addToCategories();
    $product->add();
    //set Product quantity
    StockAvailable::setQuantity($product->id, 0, joom_jshopping_products::product_quantity);
    // For adding Product images
    In JoomShopping, Product images are stored in the table
    joom_jshopping_products_images.

    Use the following code to add a Product images

    $shops = Shop::getShops(true, null, true);    
    $image = new Image();
    $image->id_product = $product->id;
    $image->cover = boolean: true or false;
    $image->position = Image::getHighestPosition($product->id) + 1;
    if (($image->validateFields(false, true)) === true &&
        ($image->validateFieldsLang(false, true)) === true &&
        $image->add()
       ) {
          $image->associateTo($shops);
          if (!AdminImportController::copyImage(
    	$product->id,
    	$image->id,
    	joom_jshopping_products_images::image_name,
    	'products'
          )) {
    	$image->delete();
          }
    }

Fourth step:

  • After Product migration is completed, Product attribute migration will start off.
  • Add a Product attribute group and attribute in PrestaShop by using the following code:In JoomShopping.
  • Product attribute groups are stored in the table ‘joom_jshopping_attr’ and Product attribute are stored in the table ‘joom_jshopping_attr_values’.
    // For adding attribute groups
    $attributeGroup = new AttributeGroup();
    $attributeGroup->name = joom_jshopping_attr::name_de-DE;
    $attributeGroup->public_name = joom_jshopping_attr::name_de-DE;
    $attributeGroup->group_type = joom_jshopping_attr::attr_type;
    $attributeGroup->add();
    // For adding a attribute
    $attribute = new Attribute();
    $attribute->name = joom_jshopping_attr_values::name_de-DE;
    $attribute->id_attribute_group = joom_jshopping_attr_values::group_id;
    $attribute->position = joom_jshopping_attr_values::value_ordering;
    $attribute->add();
    // For adding attribute images
    AdminController::uploadImage($attribute->id, joom_jshopping_attr_values::image, 'co/');

Fifth step:

  • After Product attribute migration is completed, migration of Product combination will get started. In JoomShopping, combinations are stored in the table ‘joom_jshopping_products_attr2’.
    // For adding Product combination in Prestashop by using the following code:
    $product  = new Product($productId, true, 1, 1);
    $options = array('' => array(''));
    SpecificPriceRule::disableAnyApplication();
    $combinations = array_values(AdminAttributeGeneratorController::createCombinations(array_values($options)));
    $combinationsValues = array_values(array_map(function () use ($product) {
        return array(
            'id_product' => $product->id
        );
    }, $combinations));
    $product->generateMultipleCombinations($combinationsValues, $combinations, false);
    Product::updateDefaultAttribute($product->id);

Sixth step:

  • After migration of all the Product and Attribute combinations, we have to update combination quantity and its price using the following code:
    // Code for updating combination price
      $combinationObj = new Combination();
      $combinationObj->setFieldsToUpdate(array('price' => true));
      $combinationObj->price = ;
      $combinationObj->save();
    // Code for updating combination quantity
      $combination = new Combination();
      $combination->quantity = ;
      StockAvailable::setQuantity($product->id, , );
      $combination->update();

Final step:

  • After successful migration, ensure that you remove all the JoomShopping tables remove from PrestaShop.

    Note:
    In PrestaShop,

    1. Category details are stored in the table ‘ps_category’ and ‘ps_category_lang’.
    2. Product details are stored in the table ‘ps_product’ and ‘ps_product_lang’.
    3. Product category relations are stored in the table ‘ps_category_product’.
    4. Product images are stored in the table ‘ps_image’ and ‘ps_image_lang’.
    5. Product combinations are stored in table ‘ps_product_attribute’ and ‘ps_product_attribute_combination’.
    6. Product attribute are stored in the table ‘ps_attribute’ and ‘ps_attribute_lang’.
    7. Product attribute group are stored in the table ‘ps_attribute_group’ and ‘ps_attribute_group_lang’.

Problem: 2

If a Product has more than one Category then the Product URL is not displaying properly. For example, Product A is assigned to two Categories C1 and C2. If we select Category C1 and choose Product A (OR) select the Category C2 and select the Product A, in both cases, it goes to the Product details page with the same URL which is based on the Category C1 because the Product’s default Category is C1(this is a default functionality of PrestaShop). But we don’t want the same URL, it should be as follows:

‘http://www.example.com/C1/A’,

‘http://www.example.com/C2/A’.

To achieve this, we have customize the core files.

Solution: 2

In PrestaShop, the Product link generation is done by the default Category, This is the reason we are getting the same URL if we enter into the both Category C1 and C2. Instead of taking the default Category, we will find the user entered categoryId and generate Product link based on that Category ID. To achieve this we have to customize the file classes/Link.php.

Code:

In the method Link::getProductLink():

if ($dispatcher->hasKeyword('product_rule', $idLang, 'categories', $idShop)) {
  $product	 = $this->getProductObject($product, $idLang, $idShop);
  $parentCatId = $this->getCategoryIdFrmUri($product, $idLang);
  $params['category'] = !$parentCatId ? ((!$category) ? $product->category : $category) : $parentCatId;
  $cats = array();
  foreach ($product->getParentCategories($idLang, $parentCatId) as $cat) {
    if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
      //remove root and home category from the URL
      $cats[] = $cat['link_rewrite'];
    }
  }
  $params['categories'] = implode('/', $cats);
}

protected function getCategoryIdFrmUri($product, $idLang) {
  $uriSplits   = explode('/', $_SERVER['REQUEST_URI']);
  if (empty($uriSplits) || !$product) {
    return null;
  }

  $latestSplit = $uriSplits[count($uriSplits) - 1];
  $latestParentAlias = explode('?', $latestSplit)[0];
  if ($product->link_rewrite === $latestParentAlias) {
    $latestParentAlias = isset($uriSplits[count($uriSplits) - 2])
    ? $uriSplits[count($uriSplits) - 2] : '';
  }
  if (!empty($latestParentAlias)) {
    $parentCat = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(
    'SELECT * FROM `' . _DB_PREFIX_ . 'category_lang` 
    WHERE `id_lang` = ' . $idLang . '
    AND `id_shop` = 1
    AND `link_rewrite` = "' . pSQL($latestParentAlias) . '"'
    );

    if (!empty($parentCat) && !empty($parentCat['id_category']) &&
    in_array($parentCat['id_category'], $product->getCategories())) {
      return $parentCat['id_category'];
    }
  }
  return null;
}

Problem: 3

In PrestaShop, if any of the Product and its Category have same rewrite link then the Product link will not work and it always points to that Category. But in our case, if Product and Category have same rewrite link, that Product and Category link have to work.

Solution: 3

To fix this issue, we have customize the file classes/Dispatcher.php.

For example: Assume a Product and its Category have rewrite link ‘sample’. The Product URL like as www.example.com/sample/sample. The Category URL will be www.example.com/sample. If we load both URLs, both redirect to Category page. But actually if we load the Product URL it should redirect to Product page and for Category URL it should redirect to Category page.

Code:

Add the below code in the Dispatcher::getController() method:

// If the category and Product slug both are same and user enter into Product with that case then we have to set controller as product
$uriSplits = explode('/', $this->request_uri);
if ( !empty($uriSplits) &&
  !preg_match('/[0-9a-zA-Z\-\/\_\s]*\.[jpg|png|js|css]+$/', $this->request_uri) ) {
  $totalSplits     = count($uriSplits);
  $latestSplit     = $uriSplits[$totalSplits - 1];
  $lastParentAlias = explode('?', $latestSplit)[0];
  $previousParentAlias = isset($uriSplits[$totalSplits - 2])
    ? $uriSplits[$totalSplits - 2] : '';
  if (
    !empty($previousParentAlias) &&
    ($previousParentAlias === $lastParentAlias)
  ) {
    $product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(
      'SELECT * FROM `' . _DB_PREFIX_ . 'product_lang` 
      WHERE `id_lang` = 1
      AND `id_shop` = 1
      AND `link_rewrite` = "' . pSQL($lastParentAlias) . '"'
    );
    if ($product) {
        $controller = 'product';
        $_POST['id_product'] = $product['id_product'];
    }
  }
}
Note: We have used the module 'pretty URLS' to avoid the Ids from the Product URL.
  • Facebook
  • Twitter
  • Tumblr
  • Pinterest
  • Google+
  • LinkedIn
  • E-Mail

About The Author

C.E.O. SoftSolutions4U

Leave a reply Cancel reply

Your email address will not be published. Required fields are marked *

contact us

SoftSolutions4U - Digital Transformation Company

Our expertise includes IoT Device Data Visualization, CRM implementation and Designing Accessible Websites.

Categories

  • IonicPressApp Push Notify Integration
  • PrestaShop
  • Recent
  • Social Media Marketing
  • The Business Show- London
  • TYPO3
  • TYPO3-Templates
  • Vue js
  • WEConnect International Europe
  • Wix vs WordPress

ABOUT

We take time to understand your business and create a strategy to fulfil your commercial objectives.

More

LATEST NEWS

  • Why Laravel is ideal framework for a business web application
  • Top 6 technical hitches and how to overcome them with Laravel
  • Wix vs WordPress
  • How to modify the events module to be displayed as a product in prestashop

Latest Project

viviapp-home
vivikola-home-1
lake view
web app for online payment
surfer on snow

Contact Info

Kemp House, 152 City Road,
London EC1V 2NX.
Phone: +44 20 3239 0140 E-Mail: info@softsolutions4u.com Web: www.softsolutions4u.com
© 2023 Soft Solutions4U
Sitemap
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT