/** * Create new translation * * POST /api/translations */ public function postAction() { $useNumberAsId = (bool) $this->Request()->getParam('useNumberAsId', 0); $params = $this->Request()->getPost(); if ($useNumberAsId) { $translation = $this->resource->createByNumber($params); } else { $translation = $this->resource->create($params); } $location = $this->apiBaseUrl . 'translations/' . $translation['id']; $data = array('id' => $translation['id'], 'location' => $location); $this->View()->assign(array('success' => true, 'data' => $data)); $this->Response()->setHeader('Location', $location); }
public function createUnitTranslations(array $unitIds, $shopId, array $translation = array()) { $data = array('type' => 'config_units', 'key' => 1, 'shopId' => $shopId, 'data' => array()); foreach ($unitIds as $id) { if (isset($translation[$id])) { $data['data'][$id] = array_merge($this->getUnitTranslation(), $translation[$id]); } else { $data['data'][$id] = $this->getUnitTranslation(); } } $this->translationApi->create($data); }
/** * @expectedException \Shopware\Components\Api\Exception\CustomValidationException */ public function testMissingDataIsArrayException() { $data = $this->getDummyData('article'); $data['data'] = 1; $this->resource->create($data); }
/** * Create the TS-Article translation * * @param ArticleModel $articleModel * @param bool $isUpdate * @throws ParameterMissingException */ private function createArticleTranslation(ArticleModel $articleModel, $isUpdate = false) { /* @var Translation $translationResource */ $translationResource = new Translation(); $translationResource->setManager($this->em); if ($isUpdate) { $translationResource->update($articleModel->getId(), $this->getTranslationArray()); } else { $translationResource->create(array_merge(array('key' => $articleModel->getId()), $this->getTranslationArray())); } }