I am invoking an entity creation using the same code from another module. I am seeing the records in the database even without invoking $entity->save();

However, these records are written twice in the database although invoked once.

When I add $entity->save() to the code after the create method, several more duplicates are created.

Is there some kind of finalizing method I should be invoking? Does this happen normally but then those records drop off on cron run?

Code:

$newEntity = $entityManager->getStorage('shopify_product')->create((array) $result->product);
$newEntity->save();

Input of $result->product

Array
(
    [id] => 415339020317
    [title] => Item Ttitle
    [body_html] => Here's the description
    [vendor] => xxxx-fx
    [product_type] => Inventory
    [created_at] => 2018-02-14T13:02:53-08:00
    [handle] => xxxx-xxxxx-xxxx
    [updated_at] => 2018-02-14T13:02:53-08:00
    [published_at] => 
    [template_suffix] => 
    [published_scope] => global
    [tags] => Tags, Go, Here
    [variants] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 5787642920989
                    [product_id] => 415339020317
                    [title] => Default Title
                    [price] => 24.95
                    [sku] => xxxxxx
                    [position] => 1
                    [inventory_policy] => continue
                    [compare_at_price] => 
                    [fulfillment_service] => manual
                    [inventory_management] => shopify
                    [option1] => Default Title
                    [option2] => 
                    [option3] => 
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [taxable] => 1
                    [barcode] => 
                    [grams] => 136
                    [image_id] => 
                    [inventory_quantity] => 146
                    [weight] => 0.3
                    [weight_unit] => lb
                    [inventory_item_id] => 5784686460957
                    [old_inventory_quantity] => 146
                    [requires_shipping] => 1
                )

        )

    [options] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 629058568221
                    [product_id] => 415339020317
                    [name] => Title
                    [position] => 1
                    [values] => Array
                        (
                            [0] => Default Title
                        )

                )

        )

    [images] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1729978728477
                    [product_id] => 415339020317
                    [position] => 1
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/xxxx/59xxxx62/products/xxxxx-full.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

            [1] => stdClass Object
                (
                    [id] => 1729978761245
                    [product_id] => 415339020317
                    [position] => 2
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/xxxx/596xxxx2/products/615xxxxx94-alt1.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

            [2] => stdClass Object
                (
                    [id] => 1729978794013
                    [product_id] => 415339020317
                    [position] => 3
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/xxxx/xxxx/products/xxxxx-alt2.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

            [3] => stdClass Object
                (
                    [id] => 1729978826781
                    [product_id] => 415339020317
                    [position] => 4
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/xxxx/xxxx/products/xxxxx-alt3.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

            [4] => stdClass Object
                (
                    [id] => 1729978859549
                    [product_id] => 415339020317
                    [position] => 5
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/1120/5962/products/61594-alt4.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

            [5] => stdClass Object
                (
                    [id] => 1729978892317
                    [product_id] => 415339020317
                    [position] => 6
                    [created_at] => 2018-02-14T13:02:53-08:00
                    [updated_at] => 2018-02-14T13:02:53-08:00
                    [width] => 740
                    [height] => 416
                    [src] => https://cdn.shopify.com/s/files/1/xxxx/xxxx/products/xxxxx-alt5.png?v=1518642173
                    [variant_ids] => Array
                        (
                        )

                )

        )

    [image] => stdClass Object
        (
            [id] => 1729978728477
            [product_id] => 415339020317
            [position] => 1
            [created_at] => 2018-02-14T13:02:53-08:00
            [updated_at] => 2018-02-14T13:02:53-08:00
            [width] => 740
            [height] => 416
            [src] => https://cdn.shopify.com/s/files/1/xxxx/xxxx/products/xxxxx-full.png?v=1518642173
            [variant_ids] => Array
                (
                )

        )

)

Comments

wickedskaman’s picture

Nevermind. I am a fool. I fixed it.

I was invoking it by bootstrapping the Drupal kernal so the save behavior is not normal, I guess. Create was enough.

Steve Ramos
www.zapcrunch.com