/**
  * Deletes a page of invalid data
  *
  * @param integer $start
  * @param integer $offset
  */
 public function deleteInvalidData($start, $offset)
 {
     // Customer group
     $customerGroupKey = PlentymarketsConfig::getInstance()->getDefaultCustomerGroupKey();
     $customerGroupRepository = Shopware()->Models()->getRepository('Shopware\\Models\\Customer\\Group');
     $customerGroups = $customerGroupRepository->findBy(array('key' => $customerGroupKey));
     $customerGroup = array_pop($customerGroups);
     foreach ($this->getInvalidData($start, $offset) as $data) {
         try {
             /** @var \Shopware\Models\Article\Article $Item */
             $Item = Shopware()->Models()->find('\\Shopware\\Models\\Article\\Article', $data['itemId']);
             $detail = new \Shopware\Models\Article\Detail();
             $detail->setArticle($Item);
             // The number will be changed by the sync process
             $detail->setNumber(PlentymarketsImportItemHelper::getItemNumber());
             $price = new Shopware\Models\Article\Price();
             $price->setFrom(1);
             $price->setPrice(1);
             $price->setPercent(0);
             $price->setArticle($Item);
             $price->setDetail($detail);
             $price->setCustomerGroup($customerGroup);
             $Item->setMainDetail($detail);
             Shopware()->Models()->persist($Item);
             Shopware()->Models()->remove($Item);
         } catch (Exception $E) {
         }
     }
     Shopware()->Models()->flush();
 }
 /**
  * @param  array $params
  * @return \Shopware\Models\Article\Price
  * @throws \Shopware\Components\Api\Exception\ValidationException
  * @throws \Exception
  */
 public function create(array $params)
 {
     $this->checkPrivilege('create');
     $params = $this->prepareArticlePriceData($params);
     $articlePrice = new \Shopware\Models\Article\Price();
     $articlePrice->fromArray($params);
     $violations = $this->getManager()->validate($articlePrice);
     if ($violations->count() > 0) {
         throw new ApiException\ValidationException($violations);
     }
     $this->getManager()->persist($articlePrice);
     $this->flush();
     return $articlePrice;
 }
    /**
     * Deletes a page of invalid data
     *
     * @param integer $start
     * @param integer $offset
     */
    public function deleteInvalidData($start, $offset)
    {
        // Controller
        $controller = new PlentymarketsImportControllerItem();
        // StoreIds
        $stores = Shopware()->Db()->fetchAll('
			SELECT plentyID FROM plenty_mapping_shop
		');
        // Customer group
        $customerGroupKey = PlentymarketsConfig::getInstance()->getDefaultCustomerGroupKey();
        $customerGroupRepository = Shopware()->Models()->getRepository('Shopware\\Models\\Customer\\Group');
        $customerGroups = $customerGroupRepository->findBy(array('key' => $customerGroupKey));
        $customerGroup = array_pop($customerGroups);
        //
        foreach ($this->getInvalidData($start, $offset) as $data) {
            PyLog()->message('Fix:Item:Price', 'Start of fixing corrupt prices of the item id ' . $data['itemId']);
            // Search
            foreach (explode(',', $data['detailIds']) as $detailId) {
                try {
                    /** @var \Shopware\Models\Article\Detail $Detail */
                    $Detail = Shopware()->Models()->find('\\Shopware\\Models\\Article\\Detail', $detailId);
                    $price = new Shopware\Models\Article\Price();
                    $price->setFrom(1);
                    $price->setPrice(1);
                    $price->setPercent(0);
                    $price->setArticle($Detail->getArticle());
                    $price->setDetail($Detail);
                    $price->setCustomerGroup($customerGroup);
                    Shopware()->Models()->persist($price);
                } catch (Exception $E) {
                    PyLog()->debug($E->getMessage());
                }
            }
            Shopware()->Models()->flush();
            PyLog()->message('Fix:Item:Price', 'Finished with the fixing corrupt prices of the item id »' . $data['itemId'] . '«');
            try {
                foreach ($stores as $store) {
                    // Update the complete item from plenty
                    $controller->importItem(PlentymarketsMappingController::getItemByShopwareID($data['itemId']), $store['plentyID']);
                }
            } catch (Exception $e) {
                PyLog()->error('Fix:Item:Price', $e->getMessage());
            }
            // Stop after the first
            break;
        }
    }