Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commerce Products field not mapping to Title or Slug on import #569

Closed
amityweb opened this issue Jul 4, 2019 · 12 comments
Closed

Commerce Products field not mapping to Title or Slug on import #569

amityweb opened this issue Jul 4, 2019 · 12 comments
Labels

Comments

@amityweb
Copy link

amityweb commented Jul 4, 2019

I have mapped a XML import element to the field Commerce Product inside a matrix field. I have chosen Data Provided this Entry is: Slug AND I also tried Title.

The relationship is not imported.

Here is the FeedMe setting, also tried Title:

Screenshot at Jul 04 16-43-49

Here is the XML setup as referenced in the setting above. I added CDATA due to characters, but when using slug I did not add CDATA.

Screenshot at Jul 04 17-01-37

Here is the content block with no relationship, even though the other products exist (I did an import several times) and are in the feed:

Screenshot at Jul 04 17-01-17

If I switch the field to a Commerce Variant (because I can still see all the products in the list) it still does not work.

If I don't put the Related Field in a Matrix block, so its its own separate field, it also does not work.

FeedMe: v4.1.0
Craft CMS: Craft Solo 3.2.0-RC2

Update 1
When I do an import, this is the query array created in src/fields/CommerceProducts.php, but it does not return any matches. So is the query array correct?

Array
(
    [siteId] => 1
    [status] => 
    [typeId] => Array
        (
            [0] => b755d0ac-93fb-4de5-9b00-8ca3fa970af0
        )

    [limit] => 
    [where] => Array
        (
            [0] => =
            [1] => slug
            [2] => mcs-64
        )
)

The only other hunch is if I am relating to entries in my import, are perhaps all entries deleted first, and then when it imports the entry with those slugs dont exist? I can't imagine it woudl do this, I have chosen settings Add & Update.

Update 2

I believe the array is wrong and so the created SQL is wrong. The created SQL is as follows and includes WHERE (commerce_products.typeId='b755d0ac-93fb-4de5-9b00-8ca3fa970af0') - but typeId is not a uid in commerce_products, and even then, the above ID is not a commerce_product uid anyway, but the commerce_producttypes uid.

SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `commerce_products`.`id`, `commerce_products`.`typeId`, `commerce_products`.`promotable`, `commerce_products`.`freeShipping`, `commerce_products`.`postDate`, `commerce_products`.`expiryDate`, `commerce_products`.`defaultPrice`, `commerce_products`.`defaultVariantId`, `commerce_products`.`defaultSku`, `commerce_products`.`defaultWeight`, `commerce_products`.`defaultLength`, `commerce_products`.`defaultWidth`, `commerce_products`.`defaultHeight`, `commerce_products`.`taxCategoryId`, `commerce_products`.`shippingCategoryId`, `commerce_products`.`availableForPurchase`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_address`, `content`.`field_countryName`, `content`.`field_customLink`, `content`.`field_customSolutionsText`, `content`.`field_customSolutionsVideo`, `content`.`field_duplicated`, `content`.`field_mapCode`, `content`.`field_moreInfoPopUpText`, `content`.`field_oldSiteParentId`, `content`.`field_oldSitePostId`, `content`.`field_openingText`, `content`.`field_pageTitleOverride`, `content`.`field_phoneNumber`, `content`.`field_showDuplicatedProductContent`, `content`.`field_siteEnabled`, `content`.`field_specialistCategory`, `content`.`field_nonTranslatableTitle`, `content`.`field_uniqueIdentifier`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`
FROM `elements` `elements`
INNER JOIN `commerce_products` `commerce_products` ON `commerce_products`.`id` = `elements`.`id`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `content` `content` ON (`content`.`elementId` = `elements`.`id`) AND (`content`.`siteId` = `elements_sites`.`siteId`)
WHERE (`commerce_products`.`typeId`='b755d0ac-93fb-4de5-9b00-8ca3fa970af0') AND (`slug` = 'mcs-64') AND (`elements_sites`.`siteId`='1') AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements_sites`.`enabled`=TRUE) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY `commerce_products`.`postDate` DESC) `subquery`
INNER JOIN `commerce_products` `commerce_products` ON `commerce_products`.`id` = `subquery`.`elementsId`
INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `content` `content` ON `content`.`id` = `subquery`.`contentId`
ORDER BY `commerce_products`.`postDate` DESC

If I just delete that part, it returns the correct related products.

Note: in the field settings I chose a Type to relate products to. I have not tried doing it with All selected. Maybe its only apparent when a Type is chosen.

So commenting out this in the file, makes it work for me for the normal field, but it still does not import into the matrix field as I guess thats managed in the Matrix field file.
//$criteria['typeId'] = $typeIds;

I will change the way I am building this site to utilise its own related field and not in Matrix, but this obviously should be addressed anyway.

@amityweb amityweb changed the title Commerce Products field (inside Matrix field) not mapping to Title or Slug on import Commerce Products field not mapping to Title or Slug on import Jul 4, 2019
@brandonkelly
Copy link
Member

Do you have a database backup from before you switched away from Matrix? If so can you please send that and your composer.json + composer.lock files over to [email protected]?

@leigeber
Copy link

Same issue here when specific product types are selected due to the UID criteria instead of integer for the product type ID. This is a hack but the quick fix for import was adding the following after line 52 in feed-me/src/fields/CommerceProducts.php.

$typeIds = array_column(ProductType::findAll([
    'uid' => $typeIds
]), 'id');

@jonXmack
Copy link

Can confirm when selecting a specific product type (Source) it doesn't work, but when the All checkbox is checked it imports fine.

@moldedjelly
Copy link

I noticed this too. I had my field set with certain product type. Had to change it to "All" then FeedMe setup the relations perfectly.

@epapada
Copy link

epapada commented Feb 11, 2020

Hello. It is not mapping using Craft 3.4.5 and Feed Me 4.2.0.1 I do not see an option "All" or a checkbox when selecting a product type [ https://www.screencast.com/t/9NIlY9JAX ] and if I leave this to "none" I get an error on the next page (with debug mode on) Argument 1 passed to craft\commerce\services\ProductTypes::getProductTypeById() must be of the type integer, string given Tried the above fix @leigeber but the code has change a lot now and it doesn't do much.

@epapada
Copy link

epapada commented Feb 25, 2020

@moldedjelly Hello. Where did you change it to "all" - I cannot find it in Feed Me plugin. I need to migrate hundreds of products and so far I haven't found a way to map product to product relation :(

@moldedjelly
Copy link

@epapada hi. I'm not sure your case is the same as this thread. My understanding was this thread was about importing product slug/title data and matching it into a Commerce Products entries field within elements being imported by FeedMe.

@epapada
Copy link

epapada commented Feb 25, 2020

@moldedjelly Thanks for the quick reply! My scenario is trying to match Commerce products on other Commerce products (related products field) of the same type by ID (tried with title and slug but no lack). Feed me finds the product but it skips it saying "no content has changed". I tried it with the simplest csv file with direct ids but no lack. For example my csv is like this productID,newProduct 8928,9858 I am then mapping productID to product ID and newProduct for the related product field [ https://www.screencast.com/t/1v0qpe7OB3 ].

@Saboteur777
Copy link

@epapada You can filter which Product Types are allowed for selection in a specific Commerce Products fields (in your case in the related product field, getPricesFromProduct).

Saboteur777 added a commit to webmenedzser/feed-me that referenced this issue Aug 4, 2020
Following [leigeber's answer](craftcms#569 (comment)), this is a quick fix to work around craftcms#569.
@Saboteur777
Copy link

Well, there is a PR already open: #522

@anchovy
Copy link

anchovy commented Dec 2, 2020

I've got the same issue where if I limit the commerce field to the Sources product type that I want to select from my mapping doesn't work - but if I set the Sources to all product types it does work.

But because some of my Commerce Product have the same title/slug in different product types it's sometimes selecting the wrong one.

Product Type: Location
Outside
Inside
Kitchen
Wet

Product Type: Use
Outside -> mapping to Use>Outside
Outside Wet -> mapping to Use>Outside
Outside Dry -> mapping to Use>Outside
Inside -> mapping to Location>Inside
Wet -> mapping to Location>Wet
Kitchen -> mapping to Location>Kitchen

As a fix I've made my slug's unique, but I don't think I should have to do this :(

@pdaleramirez pdaleramirez added 🔎 status: investigating Trying to reproduce and removed 🔎 status: investigating Trying to reproduce labels Apr 26, 2023
@pdaleramirez
Copy link
Contributor

I’ve tested this, and I’m unable to replicate the bug. I’ve tried the product field with All and specific product type sources; both were imported. It could be that this had been fixed on the latest Feed-me v4 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants