Example #1
0
 /**
  * Refresh the top seller data of a single article.
  * @param Enlight_Event_EventArgs $arguments
  */
 public function refreshArticle(Enlight_Event_EventArgs $arguments)
 {
     if (!$this->isTopSellerActivated()) {
         return;
     }
     /**@var $article \Shopware\Models\Article\Article*/
     $article = $arguments->getEntity();
     if (!$article instanceof \Shopware\Models\Article\Article) {
         return;
     }
     if (!$article->getId() > 0) {
         return;
     }
     $this->TopSeller()->refreshTopSellerForArticleId($article->getId());
 }
Example #2
0
    /**
     * @param Enlight_Event_EventArgs $eventArgs
     */
    public function onPostPersist(Enlight_Event_EventArgs $eventArgs)
    {
        if(empty($this->Config()->proxyBan)) {
            return;
        }
        if($this->proxyUrl === null || $this->request->getHeader('Surrogate-Capability') === false) {
            return;
        }

        $entity = $eventArgs->get('entity');
        if ($entity instanceof \Doctrine\ORM\Proxy\Proxy) {
            $entityName = get_parent_class($entity);
        } else {
            $entityName = get_class($eventArgs->getEntity());
        }

        $categoryIds = array();
        $articleIds = array();

        switch ($entityName) {
            case 'Shopware\Models\Article\Article':
                $articleIds[] = $entity->getId();
                foreach ($entity->getCategories() as $category) {
                    $categoryIds[] = $category->getId();
                }
                break;
            case 'Shopware\Models\Category\Category':
                $categoryIds[] = $entity->getId();
                break;
            case 'Shopware\Models\Banner\Banner':
                $categoryIds[] = $entity->getCategoryId();
                break;
        }

        $client = new Zend_Http_Client(null, array(
            'useragent' => 'Shopware/' . Shopware()->Config()->version,
            'timeout' => 5,
        ));

        try {
            foreach ($categoryIds as $categoryId) {
                $client->setUri(
                    $this->proxyUrl . urlencode('c-' . $categoryId)
                )->request('BAN');
            }
            foreach ($articleIds as $articleId) {
                $client->setUri(
                    $this->proxyUrl . urlencode('a-' . $articleId)
                )->request('BAN');
            }
        } catch(Exception $e) { }
    }