private function retrievePathScope($path, $shopNumber)
    {
        $shopConfigs = $this->getShopNumberCollection($shopNumber);

        if (!$shopConfigs->getSize()) {
            throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_UNKNOWN_SHOP_NUMBER, false, true);
        }

        $firstItem = $shopConfigs->getFirstItem();

        /**
         * todo-sg: should be improved to use a single query, e.g. (scope = x AND scope_id = x) OR (scope = ...)
         *
         * @var Value $shopConfig
         */
        foreach ($shopConfigs as $shopConfig) {
            /** @var Collection $collection */
            $collection = $this
                ->getCollectionByPath($path)
                ->addFieldToFilter('scope', $shopConfig->getScope())
                ->addFieldToFilter('scope_id', $shopConfig->getScopeId());

            if ($collection->getItems()) {
                /** @var Value $propertyConfig */
                $propertyConfig = $collection->setOrder('scope_id')->getFirstItem();
                if ($propertyConfig->getData('value')) {
                    return $propertyConfig;
                }
            }
        }

        return $firstItem;
    }
private function retrievePathScope($path, $shopNumber)
    {
        $shopConfigs = $this->getShopNumberCollection($shopNumber);

        if (!$shopConfigs->getSize()) {
            throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_UNKNOWN_SHOP_NUMBER, false, true);
        }

        $firstItem = $shopConfigs->getFirstItem();

        /**
         * todo-sg: should be improved to use a single query, e.g. (scope = x AND scope_id = x) OR (scope = ...)
         *
         * @var Value $shopConfig
         */
        foreach ($shopConfigs as $shopConfig) {
            /** @var Collection $collection */
            $collection = $this
                ->getCollectionByPath($path)
                ->addFieldToFilter('scope', $shopConfig->getScope())
                ->addFieldToFilter('scope_id', $shopConfig->getScopeId());

            if ($collection->getItems()) {
                /** @var Value $propertyConfig */
                $propertyConfig = $collection->setOrder('scope_id')->getFirstItem();
                if ($propertyConfig->getData('value')) {
                    return $propertyConfig;
                }
            }
        }

        return $firstItem;
    }
private function retrievePathScope ( $ path , $ shopNumber ) { $ shopConfigs = $ this -> getShopNumberCollection ( $ shopNumber ) ; if ( ! $ shopConfigs -> getSize ( ) ) { throw new ShopgateLibraryException ( ShopgateLibraryException :: PLUGIN_API_UNKNOWN_SHOP_NUMBER , false , true ) ; } $ firstItem = $ shopConfigs -> getFirstItem ( ) ; /**
         * todo-sg: should be improved to use a single query, e.g. (scope = x AND scope_id = x) OR (scope = ...)
         *
         * @var Value $shopConfig
         */ foreach ( $ shopConfigs as $ shopConfig ) { /** @var Collection $collection */ $ collection = $ this -> getCollectionByPath ( $ path ) -> addFieldToFilter ( 'scope' , $ shopConfig -> getScope ( ) ) -> addFieldToFilter ( 'scope_id' , $ shopConfig -> getScopeId ( ) ) ; if ( $ collection -> getItems ( ) ) { /** @var Value $propertyConfig */ $ propertyConfig = $ collection -> setOrder ( 'scope_id' ) -> getFirstItem ( ) ; if ( $ propertyConfig -> getData ( 'value' ) ) { return $ propertyConfig ; } } } return $ firstItem ; }
Edge case checker, handles scenarios when multiple
scope id's have the same shop number.
Traverses the given collection of shopConfigs
to check whether a value in a given path exists.
If not, returns the first item of the collection.

@param string $path
@param string $shopNumber

@return Value | \Magento\Framework\DataObject
@throws ShopgateLibraryException
Edge case checker handles scenarios when multiple scope id s have the same shop number . Traverses the given collection of shopConfigs to check whether a value in a given path exists . If not returns the first item of the collection .