/** * Create snippet action */ public function createSnippetAction() { $snippets = $this->Request()->getPost(); $result = array(); if (array_key_exists('namespace', $snippets)) { $snippets = array($snippets); } foreach ($snippets as $params) { $snippet = new Snippet(); $snippet->fromArray($params); $snippet->setDirty(true); try { Shopware()->Models()->persist($snippet); Shopware()->Models()->flush(); } catch (Exception $e) { $this->View()->assign(array('success' => false, 'message' => $e->getMessage())); return; } $result[$snippet->getId()] = Shopware()->Models()->toArray($snippet); } $this->View()->assign(array('success' => true, 'data' => $result)); }
/** * Validates the value of the snippet. Returns false if the snippet value is empty and the shopId/localeId is * not 1. * * @param Snippet $snippet * @return bool */ private function isSnippetValid(Snippet $snippet) { if (!$snippet->getValue()) { if ($snippet->getShopId() != 1 || $snippet->getLocaleId() != 1) { return false; } } return true; }
/** * Create snippet action */ public function createSnippetAction() { $params = $this->Request()->getPost(); $snippet = new Snippet(); $snippet->fromArray($params); try { Shopware()->Models()->persist($snippet); Shopware()->Models()->flush(); } catch (Exception $e) { $this->View()->assign(array('success' => false, 'message' => $e->getMessage())); return; } $data = Shopware()->Models()->toArray($snippet); $this->View()->assign(array('success' => true, 'data' => $data)); }
/** * Test case */ public function testShouldBePersisted() { $snippet = new Snippet(); $snippet->fromArray($this->testData); $this->em->persist($snippet); $this->em->flush(); $snippetId = $snippet->getId(); // remove from entity manager $this->em->detach($snippet); unset($snippet); $snippet = $this->repo->find($snippetId); foreach ($this->testData as $fieldname => $value) { $getMethod = 'get' . ucfirst($fieldname); $this->assertEquals($snippet->{$getMethod}(), $value); } $this->assertInstanceOf('\\DateTime', $snippet->getCreated()); $this->assertInstanceOf('\\DateTime', $snippet->getUpdated()); }