1

I am trying to understand when to is use which according to the best practice. for exg.

To get some data like (product,customer) what should be used Collection ? To set some data into product etc what should be used ?

Need some clarity in here.

Thankyou

1

1 Answer 1

1

Magento strictly follows and recommends design patterns

Collection Repository This implementation use to manipulate entity objects but not able to create new one.

$repo = $this->myRepository();
$object = $repo->getById($myId);
$object->setData('something', 'somethingDifferent');
$repo->save($object);

Collection Factory This implementation use to manipulate entity objects and able to create new one.

$object = $this->myFactory->create();
$object->setData('something', 'somethingDifferent')->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.