I needed to return some JSON for the CMS side of our site. Currently it works like so:
My Controller
passes SKUs to a CollectionAssembler
, which then gets a product category from my ProductCategory
class, and gets the rest of the product information from another model.
The CollectionAssembler
uses this data to then create a Product
object, which it hands off to the CollectionDTO
.
CollectionDTO
<?php
class Rsc_Ga_Model_CollectionDto extends Mage_Core_Model_Abstract
{
protected $_data;
public function addProduct($product)
{
$this->_data[] = array(
'sku' => $product->getSku(),
'name' => $product->getName(),
'category' => $product->getCategoryString()
);
}
public function serializeProduct()
{
return json_encode($this->_data);
}
}
My question is, am I employing the DTO/Assembler Patterns correctly? Is it okay to pass a Product
to the DTO and have it set data in this way, or is there another Object that should handle this part for me? Is it okay that the Assembler operates by creating an Object?
I feel like I'm stretching the pattern from it's original intent, and so I want to make sure I shouldn't be using something else.
Aucun commentaire:
Enregistrer un commentaire