src/Admin/ProductBulkLoader.php
public function setParent(&$obj, $val, $record)
    {
        $title = strtolower(Convert::raw2sql($val));
        if ($title) {
            // find or create parent category, if provided
            if ($parentPage = ProductCategory::get()->where(['LOWER("Title") = ?' => $title])->sort('Created', 'DESC')->first()) {
                $obj->ParentID = $parentPage->ID;
                $obj->write();
                $obj->writeToStage('Stage');
                $obj->publishSingle();
                //TODO: otherwise assign it to the first product group found
            } elseif ($this->config()->create_new_product_groups) {
                //create parent product group
                $pg = ProductCategory::create();
                $pg->setTitle($title);
                $pg->ParentID = ($this->foundParentId) ? $this->foundParentId : 0;
                $pg->writeToStage('Stage');
                $pg->publishSingle();
                $obj->ParentID = $pg->ID;
                $obj->write();
                $obj->writeToStage('Stage');
                $obj->publishSingle();
            }
        }
    }
public function setParent(&$obj, $val, $record)
    {
        $title = strtolower(Convert::raw2sql($val));
        if ($title) {
            // find or create parent category, if provided
            if ($parentPage = ProductCategory::get()->where(['LOWER("Title") = ?' => $title])->sort('Created', 'DESC')->first()) {
                $obj->ParentID = $parentPage->ID;
                $obj->write();
                $obj->writeToStage('Stage');
                $obj->publishSingle();
                //TODO: otherwise assign it to the first product group found
            } elseif ($this->config()->create_new_product_groups) {
                //create parent product group
                $pg = ProductCategory::create();
                $pg->setTitle($title);
                $pg->ParentID = ($this->foundParentId) ? $this->foundParentId : 0;
                $pg->writeToStage('Stage');
                $pg->publishSingle();
                $obj->ParentID = $pg->ID;
                $obj->write();
                $obj->writeToStage('Stage');
                $obj->publishSingle();
            }
        }
    }
find product group parent (ie Cateogry)